Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InitialThemeSource.php
Go to the documentation of this file.
1 <?php
7 
10 use Magento\Framework\DataObject\Factory as DataObjectFactory;
12 use Magento\Theme\Model\ResourceModel\ThemeFactory;
13 
20 {
26  private $deploymentConfig;
27 
33  private $themeFactory;
34 
40  private $dataObjectFactory;
41 
47  private $data;
48 
54  public function __construct(
55  DeploymentConfig $deploymentConfig,
56  ThemeFactory $themeFactory,
57  DataObjectFactory $dataObjectFactory
58  ) {
59  $this->deploymentConfig = $deploymentConfig;
60  $this->themeFactory = $themeFactory;
61  $this->dataObjectFactory = $dataObjectFactory;
62  }
63 
85  public function get($path = '')
86  {
87  if (!$this->deploymentConfig->isDbAvailable()) {
88  return [];
89  }
90 
91  if (!$this->data) {
92  $rawThemes = $this->fetchThemes();
93  $themes = [];
94 
95  foreach ($rawThemes as $themeRow) {
96  unset($themeRow['theme_id'], $themeRow['preview_image']);
97  $themePath = $themeRow['area'] . '/' . $themeRow['theme_path'];
98  $themes[$themePath] = $themeRow;
99 
100  if (isset($rawThemes[$themeRow['parent_id']]['code'])) {
101  $themes[$themePath]['parent_id'] = $rawThemes[$themeRow['parent_id']]['code'];
102  }
103  }
104 
105  $this->data = $this->dataObjectFactory->create($themes);
106  }
107 
108  return $this->data->getData($path) ?: [];
109  }
110 
116  private function fetchThemes()
117  {
119  $theme = $this->themeFactory->create();
120  $select = $theme->getConnection()->select()
121  ->from($theme->getMainTable())
122  ->order('theme_id');
123 
124  return $theme->getConnection()->fetchAssoc($select);
125  }
126 }
$deploymentConfig
__construct(DeploymentConfig $deploymentConfig, ThemeFactory $themeFactory, DataObjectFactory $dataObjectFactory)
$theme