Html.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\View\Page\Config\Reader;
  7. use Magento\Framework\View\Layout;
  8. use Magento\Framework\View\Page\Config as PageConfig;
  9. /**
  10. * Html reader is used for collecting attributes of html in to the scheduled page structure
  11. */
  12. class Html implements Layout\ReaderInterface
  13. {
  14. /**#@+
  15. * Supported types
  16. */
  17. const TYPE_HTML = 'html';
  18. /**#@-*/
  19. /**#@+
  20. * Supported html elements
  21. */
  22. const HTML_ATTRIBUTE = 'attribute';
  23. /**#@-*/
  24. /**
  25. * {@inheritdoc}
  26. *
  27. * @return string[]
  28. */
  29. public function getSupportedNodes()
  30. {
  31. return [self::TYPE_HTML];
  32. }
  33. /**
  34. * {@inheritdoc}
  35. *
  36. * @param Layout\Reader\Context $readerContext
  37. * @param Layout\Element $htmlElement
  38. * @return $this
  39. */
  40. public function interpret(
  41. Layout\Reader\Context $readerContext,
  42. Layout\Element $htmlElement
  43. ) {
  44. /** @var \Magento\Framework\View\Layout\Element $element */
  45. foreach ($htmlElement as $element) {
  46. if ($element->getName() === self::HTML_ATTRIBUTE) {
  47. $readerContext->getPageConfigStructure()->setElementAttribute(
  48. PageConfig::ELEMENT_TYPE_HTML,
  49. $element->getAttribute('name'),
  50. $element->getAttribute('value')
  51. );
  52. }
  53. }
  54. return $this;
  55. }
  56. }