Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Container.php
Go to the documentation of this file.
1 <?php
7 
9 
13 class Container implements Layout\ReaderInterface
14 {
18  const TYPE_CONTAINER = 'container';
19  const TYPE_REFERENCE_CONTAINER = 'referenceContainer';
25  const CONTAINER_OPT_HTML_TAG = 'htmlTag';
26  const CONTAINER_OPT_HTML_CLASS = 'htmlClass';
27  const CONTAINER_OPT_HTML_ID = 'htmlId';
28  const CONTAINER_OPT_LABEL = 'label';
29  const CONTAINER_OPT_DISPLAY = 'display';
33  protected $helper;
34 
38  protected $readerPool;
39 
46  public function __construct(
49  ) {
50  $this->helper = $helper;
51  $this->readerPool = $readerPool;
52  }
53 
57  public function getSupportedNodes()
58  {
60  }
61 
70  public function interpret(Context $readerContext, Layout\Element $currentElement)
71  {
72  switch ($currentElement->getName()) {
74  $this->helper->scheduleStructure(
75  $readerContext->getScheduledStructure(),
76  $currentElement,
77  $currentElement->getParent()
78  );
79  $this->mergeContainerAttributes($readerContext->getScheduledStructure(), $currentElement);
80  break;
81 
83  $this->containerReference($readerContext->getScheduledStructure(), $currentElement);
84  break;
85 
86  default:
87  break;
88  }
89  $this->readerPool->interpret($readerContext, $currentElement);
90  return $this;
91  }
92 
100  protected function mergeContainerAttributes(
101  Layout\ScheduledStructure $scheduledStructure,
102  Layout\Element $currentElement
103  ) {
104  $containerName = $currentElement->getAttribute('name');
105  $elementData = $scheduledStructure->getStructureElementData($containerName);
106 
107  if (isset($elementData['attributes'])) {
108  $keys = array_keys($elementData['attributes']);
109  foreach ($keys as $key) {
110  if (isset($currentElement[$key])) {
111  $elementData['attributes'][$key] = (string)$currentElement[$key];
112  }
113  }
114  } else {
115  $elementData['attributes'] = [
116  self::CONTAINER_OPT_HTML_TAG => (string)$currentElement[self::CONTAINER_OPT_HTML_TAG],
117  self::CONTAINER_OPT_HTML_ID => (string)$currentElement[self::CONTAINER_OPT_HTML_ID],
118  self::CONTAINER_OPT_HTML_CLASS => (string)$currentElement[self::CONTAINER_OPT_HTML_CLASS],
119  self::CONTAINER_OPT_LABEL => (string)$currentElement[self::CONTAINER_OPT_LABEL],
120  self::CONTAINER_OPT_DISPLAY => (string)$currentElement[self::CONTAINER_OPT_DISPLAY],
121  ];
122  }
123  $scheduledStructure->setStructureElementData($containerName, $elementData);
124  }
125 
136  protected function containerReference(
137  Layout\ScheduledStructure $scheduledStructure,
138  Layout\Element $currentElement
139  ) {
140  $containerName = $currentElement->getAttribute('name');
141  $containerRemove = filter_var($currentElement->getAttribute('remove'), FILTER_VALIDATE_BOOLEAN);
142  if ($containerRemove) {
143  $scheduledStructure->setElementToRemoveList($containerName);
144  return;
145  } elseif ($currentElement->getAttribute('remove')) {
146  $scheduledStructure->unsetElementFromListToRemove($containerName);
147  }
148  $this->mergeContainerAttributes($scheduledStructure, $currentElement);
149  }
150 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__construct(Layout\ScheduledStructure\Helper $helper, Layout\ReaderPool $readerPool)
Definition: Container.php:46
interpret(Context $readerContext, Layout\Element $currentElement)
Definition: Container.php:70
containerReference(Layout\ScheduledStructure $scheduledStructure, Layout\Element $currentElement)
Definition: Container.php:136
mergeContainerAttributes(Layout\ScheduledStructure $scheduledStructure, Layout\Element $currentElement)
Definition: Container.php:100