Config.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Theme\Model\Layout;
  7. /**
  8. * Page layout config model
  9. */
  10. class Config
  11. {
  12. /**
  13. * Available page layouts
  14. *
  15. * @var array
  16. */
  17. protected $_pageLayouts;
  18. /**
  19. * @var \Magento\Framework\Config\DataInterface
  20. */
  21. protected $_dataStorage;
  22. /**
  23. * Constructor
  24. *
  25. * @param \Magento\Framework\Config\DataInterface $dataStorage
  26. */
  27. public function __construct(\Magento\Framework\Config\DataInterface $dataStorage)
  28. {
  29. $this->_dataStorage = $dataStorage;
  30. }
  31. /**
  32. * Initialize page layouts list
  33. *
  34. * @return \Magento\Theme\Model\Layout\Config
  35. */
  36. protected function _initPageLayouts()
  37. {
  38. if ($this->_pageLayouts === null) {
  39. $this->_pageLayouts = [];
  40. foreach ($this->_dataStorage->get(null) as $layoutCode => $layoutConfig) {
  41. $layoutConfig['label'] = __($layoutConfig['label']);
  42. $this->_pageLayouts[$layoutCode] = new \Magento\Framework\DataObject($layoutConfig);
  43. }
  44. }
  45. return $this;
  46. }
  47. /**
  48. * Retrieve available page layouts
  49. *
  50. * @return \Magento\Framework\DataObject[]
  51. */
  52. public function getPageLayouts()
  53. {
  54. $this->_initPageLayouts();
  55. return $this->_pageLayouts;
  56. }
  57. /**
  58. * Retrieve page layout by code
  59. *
  60. * @param string $layoutCode
  61. * @return \Magento\Framework\DataObject|boolean
  62. */
  63. public function getPageLayout($layoutCode)
  64. {
  65. $this->_initPageLayouts();
  66. if (isset($this->_pageLayouts[$layoutCode])) {
  67. return $this->_pageLayouts[$layoutCode];
  68. }
  69. return false;
  70. }
  71. /**
  72. * Retrieve page layout handles
  73. *
  74. * @return array
  75. */
  76. public function getPageLayoutHandles()
  77. {
  78. $handles = [];
  79. foreach ($this->getPageLayouts() as $layout) {
  80. $handles[$layout->getCode()] = $layout->getCode();
  81. }
  82. return $handles;
  83. }
  84. }