Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Filter.php
Go to the documentation of this file.
1 <?php
7 
13 {
17  protected $_widgetResource;
18 
22  protected $_widget;
23 
42  public function __construct(
43  \Magento\Framework\Stdlib\StringUtils $string,
44  \Psr\Log\LoggerInterface $logger,
45  \Magento\Framework\Escaper $escaper,
46  \Magento\Framework\View\Asset\Repository $assetRepo,
47  \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
48  \Magento\Variable\Model\VariableFactory $coreVariableFactory,
49  \Magento\Store\Model\StoreManagerInterface $storeManager,
50  \Magento\Framework\View\LayoutInterface $layout,
51  \Magento\Framework\View\LayoutFactory $layoutFactory,
52  \Magento\Framework\App\State $appState,
53  \Magento\Framework\UrlInterface $urlModel,
54  \Pelago\Emogrifier $emogrifier,
55  \Magento\Variable\Model\Source\Variables $configVariables,
56  \Magento\Widget\Model\ResourceModel\Widget $widgetResource,
57  \Magento\Widget\Model\Widget $widget
58  ) {
59  $this->_widgetResource = $widgetResource;
60  $this->_widget = $widget;
61  parent::__construct(
62  $string,
63  $logger,
64  $escaper,
65  $assetRepo,
66  $scopeConfig,
67  $coreVariableFactory,
69  $layout,
70  $layoutFactory,
71  $appState,
72  $urlModel,
75  );
76  }
77 
84  public function generateWidget($construction)
85  {
86  $params = $this->getParameters($construction[2]);
87 
88  // Determine what name block should have in layout
89  $name = null;
90  if (isset($params['name'])) {
91  $name = $params['name'];
92  }
93 
94  // validate required parameter type or id
95  if (!empty($params['type'])) {
96  $type = $params['type'];
97  } elseif (!empty($params['id'])) {
98  $preConfigured = $this->_widgetResource->loadPreconfiguredWidget($params['id']);
99  $type = $preConfigured['widget_type'];
100  $params = $preConfigured['parameters'];
101  } else {
102  return '';
103  }
104 
105  // we have no other way to avoid fatal errors for type like 'cms/widget__link', '_cms/widget_link' etc.
106  $xml = $this->_widget->getWidgetByClassType($type);
107  if ($xml === null) {
108  return '';
109  }
110 
111  // define widget block and check the type is instance of Widget Interface
112  $widget = $this->_layout->createBlock($type, $name, ['data' => $params]);
113  if (!$widget instanceof \Magento\Widget\Block\BlockInterface) {
114  return '';
115  }
116 
117  return $widget->toHtml();
118  }
119 
126  public function widgetDirective($construction)
127  {
128  return $this->generateWidget($construction);
129  }
130 
137  public function mediaDirective($construction)
138  {
139  $params = $this->getParameters(html_entity_decode($construction[2], ENT_QUOTES));
140  return $this->_storeManager->getStore()
141  ->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . $params['url'];
142  }
143 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$storeManager
$logger
__construct(\Magento\Framework\Stdlib\StringUtils $string, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Escaper $escaper, \Magento\Framework\View\Asset\Repository $assetRepo, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Variable\Model\VariableFactory $coreVariableFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\View\LayoutInterface $layout, \Magento\Framework\View\LayoutFactory $layoutFactory, \Magento\Framework\App\State $appState, \Magento\Framework\UrlInterface $urlModel, \Pelago\Emogrifier $emogrifier, \Magento\Variable\Model\Source\Variables $configVariables, \Magento\Widget\Model\ResourceModel\Widget $widgetResource, \Magento\Widget\Model\Widget $widget)
Definition: Filter.php:42
$type
Definition: item.phtml:13
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
if(!isset($_GET['name'])) $name
Definition: log.php:14