예제 #1
0
 /**
  * Populate queue for generating structural elements
  *
  * @param Layout\ScheduledStructure $scheduledStructure
  * @param \Magento\Framework\View\Layout\Element $currentNode
  * @param \Magento\Framework\View\Layout\Element $parentNode
  * @return string
  * @see scheduleElement() where the scheduledStructure is used
  */
 public function scheduleStructure(Layout\ScheduledStructure $scheduledStructure, Layout\Element $currentNode, Layout\Element $parentNode)
 {
     // if it hasn't a name it must be generated
     if (!(string) $currentNode->getAttribute('name')) {
         $name = $this->_generateAnonymousName($parentNode->getElementName() . '_schedule_block');
         $currentNode->setAttribute('name', $name);
     }
     $path = $name = (string) $currentNode->getAttribute('name');
     // Prepare scheduled element with default parameters [type, alias, parentName, siblingName, isAfter]
     $row = [self::SCHEDULED_STRUCTURE_INDEX_TYPE => $currentNode->getName(), self::SCHEDULED_STRUCTURE_INDEX_ALIAS => '', self::SCHEDULED_STRUCTURE_INDEX_PARENT_NAME => '', self::SCHEDULED_STRUCTURE_INDEX_SIBLING_NAME => null, self::SCHEDULED_STRUCTURE_INDEX_IS_AFTER => true];
     $parentName = $parentNode->getElementName();
     //if this element has a parent element, there must be reset [alias, parentName, siblingName, isAfter]
     if ($parentName) {
         $row[self::SCHEDULED_STRUCTURE_INDEX_ALIAS] = (string) $currentNode->getAttribute('as');
         $row[self::SCHEDULED_STRUCTURE_INDEX_PARENT_NAME] = $parentName;
         list($row[self::SCHEDULED_STRUCTURE_INDEX_SIBLING_NAME], $row[self::SCHEDULED_STRUCTURE_INDEX_IS_AFTER]) = $this->_beforeAfterToSibling($currentNode);
         // materialized path for referencing nodes in the plain array of _scheduledStructure
         if ($scheduledStructure->hasPath($parentName)) {
             $path = $scheduledStructure->getPath($parentName) . '/' . $path;
         }
     }
     $this->_overrideElementWorkaround($scheduledStructure, $name, $path);
     $scheduledStructure->setPathElement($name, $path);
     $scheduledStructure->setStructureElement($name, $row);
     return $name;
 }
예제 #2
0
 /**
  * Schedule attributes to the page config structure
  *
  * @param Layout\Reader\Context $readerContext
  * @param Layout\Element $element
  * @return $this
  */
 protected function setBodyAttributeToStructure(Layout\Reader\Context $readerContext, Layout\Element $element)
 {
     if ($element->getAttribute('name') == PageConfig::BODY_ATTRIBUTE_CLASS) {
         $readerContext->getPageConfigStructure()->setBodyClass($element->getAttribute('value'));
     } else {
         $readerContext->getPageConfigStructure()->setElementAttribute(PageConfig::ELEMENT_TYPE_BODY, $element->getAttribute('name'), $element->getAttribute('value'));
     }
     return $this;
 }
예제 #3
0
 /**
  * Schedule structural changes for move directive
  *
  * @param \Magento\Framework\View\Layout\ScheduledStructure $scheduledStructure
  * @param \Magento\Framework\View\Layout\Element $currentElement
  * @throws \Magento\Framework\Exception\LocalizedException
  * @return $this
  */
 protected function scheduleMove(Layout\ScheduledStructure $scheduledStructure, Layout\Element $currentElement)
 {
     $elementName = (string) $currentElement->getAttribute('element');
     $destination = (string) $currentElement->getAttribute('destination');
     $alias = (string) $currentElement->getAttribute('as') ?: '';
     if ($elementName && $destination) {
         list($siblingName, $isAfter) = $this->beforeAfterToSibling($currentElement);
         $scheduledStructure->setElementToMove($elementName, [$destination, $siblingName, $isAfter, $alias]);
     } else {
         throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Element name and destination must be specified.'));
     }
     return $this;
 }
예제 #4
0
 /**
  * Get ui component attributes
  *
  * @param Layout\Element $element
  * @return array
  */
 protected function getAttributes(Layout\Element $element)
 {
     $attributes = [];
     foreach ($this->attributes as $attributeName) {
         $attributes[$attributeName] = (string) $element->getAttribute($attributeName);
     }
     return $attributes;
 }
예제 #5
0
 /**
  * Set metadata
  *
  * @param \Magento\Framework\View\Page\Config\Structure $pageConfigStructure
  * @param \Magento\Framework\View\Layout\Element $node
  * @return void
  */
 private function setMetadata($pageConfigStructure, $node)
 {
     if (!$node->getAttribute('name') && $node->getAttribute('property')) {
         $metadataName = $node->getAttribute('property');
     } else {
         $metadataName = $node->getAttribute('name');
     }
     $pageConfigStructure->setMetaData($metadataName, $node->getAttribute('content'));
 }
예제 #6
0
 /**
  * {@inheritdoc}
  *
  * @param Context $readerContext
  * @param Layout\Element $currentElement
  * @param Layout\Element $parentElement
  * @return $this
  */
 public function interpret(Context $readerContext, Layout\Element $currentElement)
 {
     $scheduledStructure = $readerContext->getScheduledStructure();
     $scheduledStructure->setElementToRemoveList((string) $currentElement->getAttribute('name'));
     return $this;
 }
예제 #7
0
 /**
  * Handling reference of container
  *
  * If attribute remove="true" then add the element to list remove,
  * else merge container attributes
  *
  * @param Layout\ScheduledStructure $scheduledStructure
  * @param Layout\Element $currentElement
  * @return void
  */
 protected function containerReference(Layout\ScheduledStructure $scheduledStructure, Layout\Element $currentElement)
 {
     $containerName = $currentElement->getAttribute('name');
     $containerRemove = filter_var($currentElement->getAttribute('remove'), FILTER_VALIDATE_BOOLEAN);
     if ($containerRemove) {
         $scheduledStructure->setElementToRemoveList($containerName);
     } else {
         $this->mergeContainerAttributes($scheduledStructure, $currentElement);
     }
 }
예제 #8
0
 /**
  * Run action defined in layout update
  *
  * @param \Magento\Framework\View\Layout\Element $node
  * @param \Magento\Framework\View\Layout\Element $parent
  * @return void
  */
 protected function _generateAction($node, $parent)
 {
     $configPath = $node->getAttribute('ifconfig');
     if ($configPath && !$this->_scopeConfig->isSetFlag($configPath, $this->scopeType, $this->scopeResolver->getScope())) {
         return;
     }
     $method = $node->getAttribute('method');
     $parentName = $node->getAttribute('block');
     if (empty($parentName)) {
         $parentName = $parent->getElementName();
     }
     $profilerKey = 'BLOCK_ACTION:' . $parentName . '>' . $method;
     \Magento\Framework\Profiler::start($profilerKey);
     $block = $this->getBlock($parentName);
     if (!empty($block)) {
         $args = $this->_parseArguments($node);
         $args = $this->_evaluateArguments($args);
         call_user_func_array(array($block, $method), $args);
     }
     \Magento\Framework\Profiler::stop($profilerKey);
 }
예제 #9
0
 /**
  * @param \Magento\Framework\View\Layout\Element $currentElement
  * @param string $destination
  * @param string $siblingName
  * @param bool $isAfter
  * @param string $alias
  * @param \Magento\Framework\View\Layout\Element $parentElement
  *
  * @dataProvider processDataProvider
  */
 public function testProcess($currentElement, $destination, $siblingName, $isAfter, $alias, $parentElement)
 {
     $this->scheduledStructureMock->expects($this->any())->method('setElementToMove')->with((string) $currentElement->getAttribute('element'), [$destination, $siblingName, $isAfter, $alias]);
     $this->move->interpret($this->contextMock, $currentElement, $parentElement);
 }
예제 #10
0
 /**
  * Merge Container attributes
  *
  * @param \Magento\Framework\View\Layout\ScheduledStructure $scheduledStructure
  * @param \Magento\Framework\View\Layout\Element $currentElement
  * @return void
  */
 protected function mergeContainerAttributes(Layout\ScheduledStructure $scheduledStructure, Layout\Element $currentElement)
 {
     $containerName = $currentElement->getAttribute('name');
     $elementData = $scheduledStructure->getStructureElementData($containerName);
     if (isset($elementData['attributes'])) {
         $keys = array_keys($elementData['attributes']);
         foreach ($keys as $key) {
             if (isset($currentElement[$key])) {
                 $elementData['attributes'][$key] = (string) $currentElement[$key];
             }
         }
     } else {
         $elementData['attributes'] = [self::CONTAINER_OPT_HTML_TAG => (string) $currentElement[self::CONTAINER_OPT_HTML_TAG], self::CONTAINER_OPT_HTML_ID => (string) $currentElement[self::CONTAINER_OPT_HTML_ID], self::CONTAINER_OPT_HTML_CLASS => (string) $currentElement[self::CONTAINER_OPT_HTML_CLASS], self::CONTAINER_OPT_LABEL => (string) $currentElement[self::CONTAINER_OPT_LABEL]];
     }
     $scheduledStructure->setStructureElementData($containerName, $elementData);
 }