Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Registration.php
Go to the documentation of this file.
1 <?php
7 
10 use Magento\Theme\Model\Theme\Registration as ThemeRegistration;
12 use Psr\Log\LoggerInterface;
14 use Magento\Theme\Model\Theme\Collection as ThemeCollection;
17 
22 {
26  protected $themeRegistration;
27 
31  protected $themeCollection;
32 
36  protected $themeLoader;
37 
41  protected $logger;
42 
46  protected $appState;
47 
55  public function __construct(
56  ThemeRegistration $themeRegistration,
57  ThemeCollection $themeCollection,
58  ThemeLoader $themeLoader,
59  LoggerInterface $logger,
61  ) {
62  $this->themeRegistration = $themeRegistration;
63  $this->themeCollection = $themeCollection;
64  $this->themeLoader = $themeLoader;
65  $this->logger = $logger;
66  $this->appState = $appState;
67  }
68 
78  public function beforeDispatch(
79  AbstractAction $subject,
81  ) {
82  try {
83  if ($this->appState->getMode() != AppState::MODE_PRODUCTION) {
84  $this->themeRegistration->register();
85  $this->updateThemeData();
86  }
87  } catch (LocalizedException $e) {
88  $this->logger->critical($e);
89  }
90  }
91 
97  protected function updateThemeData()
98  {
99  $themesFromConfig = $this->themeCollection->loadData();
101  foreach ($themesFromConfig as $themeFromConfig) {
103  $themeFromDb = $this->themeLoader->getThemeByFullPath(
104  $themeFromConfig->getArea()
105  . Theme::THEME_PATH_SEPARATOR
106  . $themeFromConfig->getThemePath()
107  );
108 
109  if ($themeFromConfig->getParentTheme()) {
110  $parentThemeFromDb = $this->themeLoader->getThemeByFullPath(
111  $themeFromConfig->getParentTheme()->getFullPath()
112  );
113  $themeFromDb->setParentId($parentThemeFromDb->getId());
114  }
115 
116  $themeFromDb->setThemeTitle($themeFromConfig->getThemeTitle());
117  $themeFromDb->save();
118  }
119  }
120 }
__construct(ThemeRegistration $themeRegistration, ThemeCollection $themeCollection, ThemeLoader $themeLoader, LoggerInterface $logger, AppState $appState)
beforeDispatch(AbstractAction $subject, RequestInterface $request)