/** * Create 'staging' theme associated with current 'virtual' theme * * @return \Magento\Framework\View\Design\ThemeInterface */ protected function _createStagingTheme() { $stagingTheme = $this->_themeFactory->create(); $stagingTheme->setData(['parent_id' => $this->_theme->getId(), 'theme_path' => null, 'theme_title' => sprintf('%s - Staging', $this->_theme->getThemeTitle()), 'preview_image' => $this->_theme->getPreviewImage(), 'is_featured' => $this->_theme->getIsFeatured(), 'type' => \Magento\Framework\View\Design\ThemeInterface::TYPE_STAGING]); $stagingTheme->save(); return $stagingTheme; }
/** * Find the closest physical theme among ancestors and a theme itself * * @param \Magento\Framework\View\Design\ThemeInterface $theme * @return \Magento\Theme\Model\Theme * @throws \Magento\Framework\Exception */ protected function _getPhysicalTheme(\Magento\Framework\View\Design\ThemeInterface $theme) { $result = $theme; while ($result->getId() && !$result->isPhysical()) { $result = $result->getParentTheme(); } if (!$result) { throw new \Magento\Framework\Exception("Unable to find a physical ancestor for a theme '{$theme->getThemeTitle()}'."); } return $result; }
/** * Get virtual theme title * * @param \Magento\Framework\View\Design\ThemeInterface $theme * @return string */ protected function _getVirtualThemeTitle($theme) { $themeCopyCount = $this->_themeCollection->addAreaFilter(\Magento\Framework\App\Area::AREA_FRONTEND)->addTypeFilter(\Magento\Framework\View\Design\ThemeInterface::TYPE_VIRTUAL)->addFilter('parent_id', $theme->getId())->count(); $title = sprintf("%s - %s #%s", $theme->getThemeTitle(), __('Copy'), $themeCopyCount + 1); return $title; }
/** * Find the closest physical theme among ancestors and a theme itself * * @param \Magento\Framework\View\Design\ThemeInterface $theme * @return \Magento\Theme\Model\Theme * @throws \Magento\Framework\Exception\LocalizedException */ protected function _getPhysicalTheme(\Magento\Framework\View\Design\ThemeInterface $theme) { $result = $theme; while ($result->getId() && !$result->isPhysical()) { $result = $result->getParentTheme(); } if (!$result) { throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Unable to find a physical ancestor for a theme \'%1\'.', [$theme->getThemeTitle()])); } return $result; }