Builder.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Magento validator config factory
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Theme\Model\PageLayout\Config;
  9. /**
  10. * Page layout config builder
  11. */
  12. class Builder implements \Magento\Framework\View\Model\PageLayout\Config\BuilderInterface
  13. {
  14. /**
  15. * @var \Magento\Framework\View\PageLayout\ConfigFactory
  16. */
  17. protected $configFactory;
  18. /**
  19. * @var \Magento\Framework\View\PageLayout\File\Collector\Aggregated
  20. */
  21. protected $fileCollector;
  22. /**
  23. * @var \Magento\Theme\Model\ResourceModel\Theme\Collection
  24. */
  25. protected $themeCollection;
  26. /**
  27. * @var array
  28. */
  29. private $configFiles = [];
  30. /**
  31. * @param \Magento\Framework\View\PageLayout\ConfigFactory $configFactory
  32. * @param \Magento\Framework\View\PageLayout\File\Collector\Aggregated $fileCollector
  33. * @param \Magento\Theme\Model\ResourceModel\Theme\Collection $themeCollection
  34. */
  35. public function __construct(
  36. \Magento\Framework\View\PageLayout\ConfigFactory $configFactory,
  37. \Magento\Framework\View\PageLayout\File\Collector\Aggregated $fileCollector,
  38. \Magento\Theme\Model\ResourceModel\Theme\Collection $themeCollection
  39. ) {
  40. $this->configFactory = $configFactory;
  41. $this->fileCollector = $fileCollector;
  42. $this->themeCollection = $themeCollection;
  43. $this->themeCollection->setItemObjectClass(\Magento\Theme\Model\Theme\Data::class);
  44. }
  45. /**
  46. * @inheritdoc
  47. */
  48. public function getPageLayoutsConfig()
  49. {
  50. return $this->configFactory->create(['configFiles' => $this->getConfigFiles()]);
  51. }
  52. /**
  53. * Retrieve configuration files.
  54. *
  55. * @return array
  56. */
  57. protected function getConfigFiles()
  58. {
  59. if (!$this->configFiles) {
  60. $configFiles = [];
  61. foreach ($this->themeCollection->loadRegisteredThemes() as $theme) {
  62. $configFiles[] = $this->fileCollector->getFilesContent($theme, 'layouts.xml');
  63. }
  64. $this->configFiles = array_merge(...$configFiles);
  65. }
  66. return $this->configFiles;
  67. }
  68. }