163 \
Magento\Catalog\Model\Product\Type $productType,
171 \
Magento\Framework\Data\Collection\AbstractDb $resourceCollection =
null,
172 array $relatedCacheTypes = [],
174 Json $serializer =
null 179 $this->_relatedCacheTypes = $relatedCacheTypes;
180 $this->_productType = $productType;
181 $this->_reader = $reader;
182 $this->_widgetModel = $widgetModel;
185 $this->_directory =
$filesystem->getDirectoryRead(DirectoryList::ROOT);
186 $this->_namespaceResolver = $namespaceResolver;
198 parent::_construct();
200 $this->_layoutHandles = [
206 $this->_specificEntitiesLayoutHandles = [
211 foreach (array_keys($this->_productType->getTypes()) as $typeId) {
212 $layoutHandle = str_replace(
'{{TYPE}}', $typeId, self::PRODUCT_TYPE_LAYOUT_HANDLE);
213 $this->_layoutHandles[$typeId .
'_products'] = $layoutHandle;
229 $pageGroups = $this->
getData(
'page_groups');
231 foreach ($pageGroups as $pageGroup) {
232 if (isset($pageGroup[$pageGroup[
'page_group']])) {
233 $pageGroupData = $pageGroup[$pageGroup[
'page_group']];
234 if ($pageGroupData[
'page_id']) {
235 $pageGroupIds[] = $pageGroupData[
'page_id'];
237 if (in_array($pageGroup[
'page_group'], [
'pages',
'page_layouts'])) {
238 $layoutHandle = $pageGroupData[
'layout_handle'];
240 $layoutHandle = $this->_layoutHandles[$pageGroup[
'page_group']];
242 if (!isset($pageGroupData[
'template'])) {
243 $pageGroupData[
'template'] =
'';
246 'page_id' => $pageGroupData[
'page_id'],
247 'group' => $pageGroup[
'page_group'],
248 'layout_handle' => $layoutHandle,
249 'for' => $pageGroupData[
'for'],
250 'block_reference' => $pageGroupData[
'block'],
252 'layout_handle_updates' => [$layoutHandle],
253 'template' => $pageGroupData[
'template'] ? $pageGroupData[
'template'] :
'',
255 if ($pageGroupData[
'for'] == self::SPECIFIC_ENTITIES) {
256 $layoutHandleUpdates = [];
257 foreach (explode(
',', $pageGroupData[
'entities']) as
$entity) {
258 $layoutHandleUpdates[] = str_replace(
261 $this->_specificEntitiesLayoutHandles[$pageGroup[
'page_group']]
264 $tmpPageGroup[
'entities'] = $pageGroupData[
'entities'];
265 $tmpPageGroup[
'layout_handle_updates'] = $layoutHandleUpdates;
267 $tmpPageGroups[] = $tmpPageGroup;
271 if (is_array($this->
getData(
'store_ids'))) {
272 $this->
setData(
'store_ids', implode(
',', $this->
getData(
'store_ids')));
274 $parameters = $this->
getData(
'widget_parameters');
275 if (is_array($parameters)) {
276 if (array_key_exists(
'show_pager', $parameters) && !array_key_exists(
'page_var_name', $parameters)) {
277 $parameters[
'page_var_name'] =
'p' . $this->mathRandom->getRandomString(
279 \
Magento\Framework\Math\Random::CHARS_LOWERS
283 $this->
setData(
'widget_parameters', $this->serializer->serialize($parameters));
285 $this->
setData(
'page_groups', $tmpPageGroups);
286 $this->
setData(
'page_group_ids', $pageGroupIds);
288 return parent::beforeSave();
301 return __(
'We cannot create the widget instance because it is missing required information.');
311 return $this->
getType() && $this->getThemeId();
364 return $this->
_getData(
'instance_type');
377 return \Magento\Framework\View\DesignInterface::DEFAULT_AREA;
390 if (is_string($this->
getData(
'store_ids'))) {
391 return explode(
',', $this->
getData(
'store_ids'));
393 return $this->
getData(
'store_ids');
404 if (is_string($this->
getData(
'widget_parameters'))) {
405 return $this->serializer->unserialize($this->
getData(
'widget_parameters'));
409 return is_array($this->
getData(
'widget_parameters')) ? $this->
getData(
'widget_parameters') : [];
421 $widgetsArr = $this->_widgetModel->getWidgetsArray();
422 foreach ($widgetsArr as $widget) {
423 $widgets[] = [
'value' => $widget[
$value],
'label' => $widget[
'name']];
439 $widgetsArr = $this->_widgetModel->getWidgetsArray();
440 foreach ($widgetsArr as $widget) {
441 if ($widget[$matchParam] ===
$value) {
442 $reference = $widget[$requestedParam];
457 if ($this->_widgetConfigXml ===
null) {
458 $this->_widgetConfigXml = $this->_widgetModel->getWidgetByClassType($this->
getType());
459 if ($this->_widgetConfigXml) {
460 $configFile = $this->_viewFileSystem->getFilename(
464 'theme' => $this->getThemeId(),
465 'module' => $this->_namespaceResolver->determineOmittedNamespace(
466 preg_replace(
'/^(.+?)\/.+$/',
'\\1', $this->
getType()),
472 $isReadable = $configFile
473 && $this->_directory->isReadable($this->_directory->getRelativePath($configFile));
475 $config = $this->_reader->readFile($configFile);
476 $widgetName = isset($this->_widgetConfigXml[
'name']) ? $this->_widgetConfigXml[
'name'] :
null;
477 $themeWidgetConfig =
null;
478 if ($widgetName !==
null) {
480 if (isset($widget[
'name']) && $widgetName === $widget[
'name']) {
481 $themeWidgetConfig = $widget;
486 if ($themeWidgetConfig) {
487 $this->_widgetConfigXml = array_replace_recursive($this->_widgetConfigXml, $themeWidgetConfig);
504 if ($widgetConfig && isset($widgetConfig[
'parameters']) && isset($widgetConfig[
'parameters'][
'template'])) {
505 $configTemplates = $widgetConfig[
'parameters'][
'template'];
506 if (isset($configTemplates[
'values'])) {
508 $templates[(string)
$name] = [
527 if (isset($widgetConfig) && isset($widgetConfig[
'supported_containers'])) {
528 $configNodes = $widgetConfig[
'supported_containers'];
529 foreach ($configNodes as $node) {
530 if (isset($node[
'container_name'])) {
549 if (isset($widgetConfig)) {
550 if (!isset($widgetConfig[
'supported_containers'])) {
551 return $widgetTemplates;
553 $configNodes = $widgetConfig[
'supported_containers'];
554 foreach ($configNodes as $node) {
555 if (isset($node[
'container_name']) && (
string)$node[
'container_name'] == $containerName) {
556 if (isset($node[
'template'])) {
557 $templateChildren = $node[
'template'];
558 foreach ($templateChildren as
$template) {
559 if (isset($widgetTemplates[(
string)
$template])) {
560 $templates[] = $widgetTemplates[(string)
$template];
567 return $widgetTemplates;
583 $templateFilename = $this->_viewFileSystem->getTemplateFileName(
587 'themeId' => $this->getThemeId(),
588 'module' => \
Magento\Framework\View\Element\AbstractBlock::extractModuleName($this->
getType())
595 $xml =
'<body><referenceContainer name="' . $container .
'">';
597 if (isset($parameters[
'template'])) {
598 unset($parameters[
'template']);
601 $template =
' template="' . $templatePath .
'"';
604 $hash = $this->mathRandom->getUniqueHash();
605 $xml .=
'<block class="' . $this->
getType() .
'" name="' . $hash .
'"' .
$template .
'>';
607 if (
$name ==
'conditions') {
608 $name =
'conditions_encoded';
615 $xml .=
'<action method="setData">' .
616 '<argument name="name" xsi:type="string">' .
619 '<argument name="value" xsi:type="string">' .
620 $this->_escaper->escapeHtml(
622 ) .
'</argument>' .
'</action>';
625 $xml .=
'</block></referenceContainer></body>';
637 if (count($this->_relatedCacheTypes)) {
638 $this->_cacheTypeList->invalidate($this->_relatedCacheTypes);
653 return parent::afterSave();
663 if ($this->getPageGroups()) {
666 return parent::beforeDelete();
setData($key, $value=null)
getData($key='', $index=null)
elseif(isset( $params[ 'redirect_parent']))
dataHasChangedFor($field)
if(!isset($_GET['name'])) $name