- /**
- * Register theme and recursively all its ascendants
- * Second param is optional and is used to prevent circular references in inheritance chain
- *
- * @param ThemeInterface &$theme
- * @param array $inheritanceChain
- * @return $this
- * @throws LocalizedException
- */
- protected function _registerThemeRecursively(&$theme, $inheritanceChain = [])
- {
- if ($theme->getId()) {
- return $this;
- }
- $themeModel = $this->getThemeFromDb($theme->getFullPath());
- if ($themeModel->getId()) {
- $theme = $themeModel;
- return $this;
- }
-
- $tempId = $theme->getFullPath();
- if (in_array($tempId, $inheritanceChain)) {
- throw new LocalizedException(__('Circular-reference in theme inheritance detected for "%1"', $tempId));
- }
- $inheritanceChain[] = $tempId;
- $parentTheme = $theme->getParentTheme();
- if ($parentTheme) {
- $this->_registerThemeRecursively($parentTheme, $inheritanceChain);
- $theme->setParentId($parentTheme->getId());
- }
-
- $this->_savePreviewImage($theme);
- $theme->setType(ThemeInterface::TYPE_PHYSICAL);
- $theme->save();
-
- return $this;
- }