Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
ThemeValidator Class Reference

Public Member Functions

 __construct (StoreManagerInterface $storeManager, ThemeProviderInterface $themeProvider, ValueInterface $configData)
 
 validateIsThemeInUse ($themePaths)
 

Detailed Description

Class ThemeValidator

Definition at line 17 of file ThemeValidator.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( StoreManagerInterface  $storeManager,
ThemeProviderInterface  $themeProvider,
ValueInterface  $configData 
)
Parameters
StoreManagerInterface$storeManager
ThemeProviderInterface$themeProvider
ValueInterface$configData

Definition at line 46 of file ThemeValidator.php.

50  {
51  $this->storeManager = $storeManager;
52  $this->themeProvider = $themeProvider;
53  $this->configData = $configData;
54  }
$storeManager

Member Function Documentation

◆ validateIsThemeInUse()

validateIsThemeInUse (   $themePaths)

Validate the theme if being in use in default, website, or store.

Parameters
string[]$themePaths
Returns
array

Definition at line 62 of file ThemeValidator.php.

63  {
64  $messages = [];
65  $themesById = [];
66  foreach ($themePaths as $themePath) {
67  $theme = $this->themeProvider->getThemeByFullPath($themePath);
68  $themesById[$theme->getId()] = $themePath;
69  }
70  $configData = $this->configData
71  ->getCollection()
72  ->addFieldToFilter('path', DesignInterface::XML_PATH_THEME_ID)
73  ->addFieldToFilter('value', ['in' => array_keys($themesById)]);
74  foreach ($configData as $row) {
75  switch ($row['scope']) {
76  case 'default':
77  $messages[] = '<error>' . $themesById[$row['value']] . ' is in use in default config' . '</error>';
78  break;
80  $messages[] = '<error>' . $themesById[$row['value']] . ' is in use in website '
81  . $this->storeManager->getWebsite($row['scope_id'])->getName() . '</error>';
82  break;
84  $messages[] = '<error>' . $themesById[$row['value']] . ' is in use in store '
85  . $this->storeManager->getStore($row['scope_id'])->getName() . '</error>';
86  break;
87  }
88  }
89  return $messages;
90  }
$theme

The documentation for this class was generated from the following file: