Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ThemeDependencyChecker.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Theme\Model\Theme\Data\Collection as ThemeCollection;
10 
15 {
21  private $themeCollection;
22 
28  private $themeProvider;
29 
35  private $themePackageInfo;
36 
44  public function __construct(
45  ThemeCollection $themeCollection,
46  ThemeProvider $themeProvider,
47  ThemePackageInfo $themePackageInfo
48  ) {
49  $this->themeCollection = $themeCollection;
50  $this->themeProvider = $themeProvider;
51  $this->themePackageInfo = $themePackageInfo;
52  }
53 
60  public function checkChildThemeByPackagesName($packages)
61  {
62  $themePaths = [];
63  foreach ($packages as $package) {
64  $themePath = $this->themePackageInfo->getFullThemePath($package);
65  if ($themePath) {
66  $themePaths[] = $themePath;
67  }
68  }
69  if ($themePaths) {
70  return $this->checkChildTheme($themePaths);
71  }
72 
73  return [];
74  }
75 
82  public function checkChildTheme($themePaths)
83  {
84  $messages = [];
85  $themeHasVirtualChildren = [];
86  $themeHasPhysicalChildren = [];
87  $parentChildMap = $this->getParentChildThemeMap();
88  foreach ($themePaths as $themePath) {
89  $theme = $this->themeProvider->getThemeByFullPath($themePath);
90  if ($theme->hasChildThemes()) {
91  $themeHasVirtualChildren[] = $themePath;
92  }
93  if (isset($parentChildMap[$themePath])) {
94  $themeHasPhysicalChildren[] = $themePath;
95  }
96  }
97  if (!empty($themeHasVirtualChildren)) {
98  $text = count($themeHasVirtualChildren) > 1 ? ' are parents of' : ' is a parent of';
99  $messages[] = implode(', ', $themeHasVirtualChildren) . $text . ' virtual theme.'
100  . ' Parent themes cannot be uninstalled.';
101  }
102  if (!empty($themeHasPhysicalChildren)) {
103  $text = count($themeHasPhysicalChildren) > 1 ? ' are parents of' : ' is a parent of';
104  $messages[] = implode(', ', $themeHasPhysicalChildren) . $text . ' physical theme.'
105  . ' Parent themes cannot be uninstalled.';
106  }
107  return $messages;
108  }
109 
115  private function getParentChildThemeMap()
116  {
117  $map = [];
118  $this->themeCollection->resetConstraints();
119  $this->themeCollection->clear();
121  foreach ($this->themeCollection as $theme) {
122  if ($theme->getParentTheme()) {
123  $map[$theme->getParentTheme()->getFullPath()][] = $theme->getFullPath();
124  }
125  }
126  return $map;
127  }
128 }
__construct(ThemeCollection $themeCollection, ThemeProvider $themeProvider, ThemePackageInfo $themePackageInfo)
endifif( $block->getLastPageNum()>1)( 'Page') ?></strong >< ul class $text
Definition: pager.phtml:43
$theme