52 private $constraints = [
53 self::CONSTRAINT_AREA => [],
54 self::CONSTRAINT_VENDOR => [],
55 self::CONSTRAINT_THEME_NAME => [],
63 private $themePackageList;
70 private $dirReadFactory;
81 \
Magento\Framework\Data\Collection\EntityFactory $entityFactory,
86 parent::__construct($entityFactory);
89 $this->dirReadFactory = $dirReadFactory;
103 if (!isset($this->constraints[
$type])) {
104 throw new \UnexpectedValueException(
"Constraint '$type' is not supported");
110 $this->constraints[
$type] = array_unique($this->constraints[
$type]);
120 foreach (array_keys($this->constraints) as $key) {
121 $this->constraints[$key] = [];
132 private function isAcceptable($constraintType,
$value)
134 return empty($this->constraints[$constraintType]) || in_array(
$value, $this->constraints[$constraintType]);
145 public function loadData($printQuery =
false, $logQuery =
false)
152 foreach ($this->themePackageList->getThemes() as $themePackage) {
153 if ($this->isAcceptable(self::CONSTRAINT_AREA, $themePackage->getArea())
154 && $this->isAcceptable(self::CONSTRAINT_VENDOR, $themePackage->getVendor())
155 && $this->isAcceptable(self::CONSTRAINT_THEME_NAME, $themePackage->getName())
157 $themes[] = $themePackage;
163 $this->_updateRelations()
175 protected function _updateRelations()
179 foreach ($themeItems as
$theme) {
180 $parentThemePath =
$theme->getData(
'parent_theme_path');
181 if ($parentThemePath) {
183 if (isset($themeItems[$themePath])) {
184 $theme->setParentTheme($themeItems[$themePath]);
199 foreach ($themes as $themePackage) {
217 'theme_path_pieces' => [
218 $themePackage->getVendor(),
219 $themePackage->getName(),
234 $media = $themeConfig->getMedia();
236 $parentPathPieces = $themeConfig->getParentTheme();
237 if (is_array($parentPathPieces) &&
count($parentPathPieces) == 1) {
238 $pathPieces = $pathData[
'theme_path_pieces'];
239 array_pop($pathPieces);
240 $parentPathPieces = array_merge($pathPieces, $parentPathPieces);
250 'area' => $themePackage->getArea(),
251 'theme_path' => $themePath,
252 'code' => $themeCode,
253 'theme_title' => $themeConfig->getThemeTitle(),
254 'preview_image' => $media[
'preview_image'] ? $media[
'preview_image'] :
null,
255 'parent_theme_path' => $parentPath
271 if ($filter[
'type'] ==
'and' &&
$theme->getDataUsingMethod($filter[
'field']) != $filter[
'value']) {
289 $this->_filters = [];
301 $themeDir = $this->dirReadFactory->create($themePackage->getPath());
302 if ($themeDir->isExist(
'theme.xml')) {
303 $configContent = $themeDir->readFile(
'theme.xml');
307 return $this->themeConfigFactory->create([
'configContent' => $configContent]);
318 return $item->getFullPath();
329 $optionArray = $addEmptyField ? [
'' =>
''] : [];
330 return $optionArray + $this->
_toOptionArray(
'theme_id',
'theme_title');
353 list($area, $themePath) = explode(
'/', $fullPath, 2);
355 $this->
addFilter(
'theme_path', $themePath);
addConstraint($type, $value)
const CONSTRAINT_THEME_NAME
hasTheme(ThemeInterface $theme)
toOptionArray($addEmptyField=false)
_getItemId(\Magento\Framework\DataObject $item)
getThemeByFullPath($fullPath)
_getConfigModel($themePackage)
_prepareConfigurationData($themePackage)
addFilter($field, $value, $type='and')
_preparePathData($themePackage)
_toOptionArray($valueField='id', $labelField='name', $additional=[])
__construct(\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Magento\Framework\Config\ThemeFactory $themeConfigFactory, ThemePackageList $themePackageList, ReadFactory $dirReadFactory)
loadData($printQuery=false, $logQuery=false)
addItem(\Magento\Framework\DataObject $item)
_loadFromFilesystem(array $themes)