|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Magento\PageBuilder\Model\View\File\Collector; |
| 10 | + |
| 11 | +use Magento\Framework\Component\ComponentRegistrar; |
| 12 | +use Magento\Framework\Component\DirSearch; |
| 13 | +use Magento\Framework\View\Design\ThemeInterface; |
| 14 | +use Magento\Framework\View\File\CollectorInterface; |
| 15 | +use Magento\Framework\View\File\Factory as FileFactory; |
| 16 | + |
| 17 | +/** |
| 18 | + * Source of Page Builder view files introduced by modules |
| 19 | + */ |
| 20 | +class PageBuilder implements CollectorInterface |
| 21 | +{ |
| 22 | + /** |
| 23 | + * @var DirSearch |
| 24 | + */ |
| 25 | + protected $componentDirSearch; |
| 26 | + |
| 27 | + /** |
| 28 | + * @var string |
| 29 | + */ |
| 30 | + private $subDir; |
| 31 | + |
| 32 | + /** |
| 33 | + * @var FileFactory |
| 34 | + */ |
| 35 | + private $fileFactory; |
| 36 | + |
| 37 | + /** |
| 38 | + * Constructor |
| 39 | + * |
| 40 | + * @param DirSearch $dirSearch |
| 41 | + * @param FileFactory $fileFactory |
| 42 | + * @param string $subDir |
| 43 | + */ |
| 44 | + public function __construct( |
| 45 | + DirSearch $dirSearch, |
| 46 | + FileFactory $fileFactory, |
| 47 | + $subDir = '' |
| 48 | + ) { |
| 49 | + $this->componentDirSearch = $dirSearch; |
| 50 | + $this->fileFactory = $fileFactory; |
| 51 | + $this->subDir = $subDir ? $subDir . '/' : ''; |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Retrieve files, they're only contained within the adminhtml directory |
| 56 | + * |
| 57 | + * @param \Magento\Framework\View\Design\ThemeInterface $theme |
| 58 | + * @param string $filePath |
| 59 | + * @return \Magento\Framework\View\File[] |
| 60 | + */ |
| 61 | + public function getFiles(ThemeInterface $theme, $filePath) |
| 62 | + { |
| 63 | + $adminArea = \Magento\Framework\App\Area::AREA_ADMINHTML; |
| 64 | + $result = []; |
| 65 | + $pageBuilderFiles = $this->componentDirSearch->collectFilesWithContext( |
| 66 | + ComponentRegistrar::MODULE, |
| 67 | + "view/{$adminArea}/{$this->subDir}{$filePath}" |
| 68 | + ); |
| 69 | + foreach ($pageBuilderFiles as $file) { |
| 70 | + $result[] = $this->fileFactory->create($file->getFullPath(), $file->getComponentName(), null, true); |
| 71 | + } |
| 72 | + return $result; |
| 73 | + } |
| 74 | +} |
0 commit comments