Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Body.php
Go to the documentation of this file.
1 <?php
7 
10 
14 class Body implements Layout\ReaderInterface
15 {
19  const TYPE_BODY = 'body';
25  const BODY_ATTRIBUTE = 'attribute';
29  protected $readerPool;
30 
37  {
38  $this->readerPool = $readerPool;
39  }
40 
46  public function getSupportedNodes()
47  {
48  return [self::TYPE_BODY];
49  }
50 
58  public function interpret(
59  Layout\Reader\Context $readerContext,
60  Layout\Element $bodyElement
61  ) {
63  foreach ($bodyElement as $element) {
64  if ($element->getName() === self::BODY_ATTRIBUTE) {
65  $this->setBodyAttributeToStructure($readerContext, $element);
66  }
67  }
68  $this->readerPool->interpret($readerContext, $bodyElement);
69  return $this;
70  }
71 
79  protected function setBodyAttributeToStructure(Layout\Reader\Context $readerContext, Layout\Element $element)
80  {
81  if ($element->getAttribute('name') == PageConfig::BODY_ATTRIBUTE_CLASS) {
82  $readerContext->getPageConfigStructure()->setBodyClass($element->getAttribute('value'));
83  } else {
84  $readerContext->getPageConfigStructure()->setElementAttribute(
85  PageConfig::ELEMENT_TYPE_BODY,
86  $element->getAttribute('name'),
87  $element->getAttribute('value')
88  );
89  }
90  return $this;
91  }
92 }
setBodyAttributeToStructure(Layout\Reader\Context $readerContext, Layout\Element $element)
Definition: Body.php:79
interpret(Reader\Context $readerContext, Element $element)
__construct(Layout\ReaderPool $readerPool)
Definition: Body.php:36
$element
Definition: element.phtml:12