Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Theme.php
Go to the documentation of this file.
1 <?php
10 namespace Magento\Theme\Helper;
11 
13 {
20 
24  protected $_assetRepo;
25 
31  public function __construct(
32  \Magento\Framework\App\Helper\Context $context,
33  \Magento\Framework\View\Layout\ProcessorFactory $layoutProcessorFactory,
34  \Magento\Framework\View\Asset\Repository $assetRepo
35  ) {
36  $this->_layoutProcessorFactory = $layoutProcessorFactory;
37  $this->_assetRepo = $assetRepo;
38  parent::__construct($context);
39  }
40 
51  public function getCssAssets($theme)
52  {
54  $layoutProcessor = $this->_layoutProcessorFactory->create(['theme' => $theme]);
55  $layoutElement = $layoutProcessor->getFileLayoutUpdatesXml();
56 
60  $xpathSelectorBlocks = '//block[@class="Magento\Theme\Block\Html\Head"]' .
61  '/block[@class="Magento\Theme\Block\Html\Head\Css"]/arguments/argument[@name="file"]';
62 
66  $xpathSelectorRefs = '//referenceBlock[@name="head"]' .
67  '/block[@class="Magento\Theme\Block\Html\Head\Css"]/arguments/argument[@name="file"]';
68 
69  $elements = array_merge(
70  $layoutElement->xpath($xpathSelectorBlocks) ?: [],
71  $layoutElement->xpath($xpathSelectorRefs) ?: []
72  );
73 
74  $params = [
75  'area' => $theme->getArea(),
76  'themeModel' => $theme,
77  ];
78 
79  $result = [];
80  foreach ($elements as $fileId) {
81  $fileId = (string)$fileId;
82  $result[$fileId] = $this->_assetRepo->createAsset($fileId, $params);
83  }
84  ksort($result);
85  return $result;
86  }
87 }
__construct(\Magento\Framework\App\Helper\Context $context, \Magento\Framework\View\Layout\ProcessorFactory $layoutProcessorFactory, \Magento\Framework\View\Asset\Repository $assetRepo)
Definition: Theme.php:31
$theme
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18