Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ThemeValidator.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Theme\Model;
7 
13 
18 {
19 
25  private $storeManager;
26 
32  private $themeProvider;
33 
39  private $configData;
40 
46  public function __construct(
47  StoreManagerInterface $storeManager,
48  ThemeProviderInterface $themeProvider,
49  ValueInterface $configData
50  ) {
51  $this->storeManager = $storeManager;
52  $this->themeProvider = $themeProvider;
53  $this->configData = $configData;
54  }
55 
62  public function validateIsThemeInUse($themePaths)
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  }
91 }
__construct(StoreManagerInterface $storeManager, ThemeProviderInterface $themeProvider, ValueInterface $configData)
$storeManager
$theme