/** * 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; }
/** * Assign theme to the stores * * @param \Magento\Framework\View\Design\ThemeInterface $theme * @param array $stores * @param string $scope * @return $this */ public function assignToStore($theme, array $stores = [], $scope = \Magento\Store\Model\ScopeInterface::SCOPE_STORES) { $isReassigned = false; $this->_unassignThemeFromStores($theme->getId(), $stores, $scope, $isReassigned); if ($this->_storeManager->isSingleStoreMode()) { $this->_assignThemeToDefaultScope($theme->getId(), $isReassigned); } else { $this->_assignThemeToStores($theme->getId(), $stores, $scope, $isReassigned); } if ($isReassigned) { $this->_configCache->clean(); $this->_layoutCache->clean(); } $this->_eventManager->dispatch('assign_theme_to_stores_after', ['stores' => $stores, 'scope' => $scope, 'theme' => $theme]); return $this; }
/** * Retrieve layout updates by handle * * @param string $handle * @param \Magento\Framework\View\Design\ThemeInterface $theme * @param \Magento\Framework\App\ScopeInterface $store * @return string */ public function fetchUpdatesByHandle($handle, \Magento\Framework\View\Design\ThemeInterface $theme, \Magento\Framework\App\ScopeInterface $store) { $bind = ['layout_update_handle' => $handle, 'theme_id' => $theme->getId(), 'store_id' => $store->getId()]; $result = ''; $connection = $this->getConnection(); if ($connection) { $select = $this->_getFetchUpdatesByHandleSelect(); $result = join('', $connection->fetchCol($select, $bind)); } return $result; }
/** * Retrieve layout updates by handle * * @param string $handle * @param \Magento\Framework\View\Design\ThemeInterface $theme * @param \Magento\Store\Model\Store $store * @return string */ public function fetchUpdatesByHandle($handle, \Magento\Framework\View\Design\ThemeInterface $theme, \Magento\Store\Model\Store $store) { $bind = ['layout_update_handle' => $handle, 'theme_id' => $theme->getId(), 'store_id' => $store->getId()]; $result = ''; $readAdapter = $this->_getReadAdapter(); if ($readAdapter) { $select = $this->_getFetchUpdatesByHandleSelect(); $result = join('', $readAdapter->fetchCol($select, $bind)); } return $result; }
/** * Retrieve layout updates by handle * * @param string $handle * @param \Magento\Framework\View\Design\ThemeInterface $theme * @param \Magento\Framework\App\ScopeInterface $store * @return string */ public function fetchUpdatesByHandle($handle, \Magento\Framework\View\Design\ThemeInterface $theme, \Magento\Framework\App\ScopeInterface $store) { $bind = ['theme_id' => $theme->getId(), 'store_id' => $store->getId()]; $cacheKey = implode('-', $bind); if (!isset($this->layoutUpdateCache[$cacheKey])) { $this->layoutUpdateCache[$cacheKey] = []; foreach ($this->getConnection()->fetchAll($this->_getFetchUpdatesByHandleSelect(), $bind) as $layout) { if (!isset($this->layoutUpdateCache[$cacheKey][$layout['handle']])) { $this->layoutUpdateCache[$cacheKey][$layout['handle']] = ''; } $this->layoutUpdateCache[$cacheKey][$layout['handle']] .= $layout['xml']; } } return isset($this->layoutUpdateCache[$cacheKey][$handle]) ? $this->layoutUpdateCache[$cacheKey][$handle] : ''; }
/** * Pass data to the Toolbar panel blocks that is needed for rendering * * @param ThemeInterface $theme * @param ThemeInterface $editableTheme * @param string $mode * @return $this */ protected function _configureToolbarBlocks($theme, $editableTheme, $mode) { /** @var $toolbarBlock \Magento\DesignEditor\Block\Adminhtml\Editor\Toolbar\Buttons */ $toolbarBlock = $this->_view->getLayout()->getBlock('design_editor_toolbar_buttons'); $toolbarBlock->setThemeId($editableTheme->getId())->setVirtualThemeId($theme->getId())->setMode($mode); /** @var $saveButtonBlock \Magento\DesignEditor\Block\Adminhtml\Editor\Toolbar\Buttons\Save */ $saveButtonBlock = $this->_view->getLayout()->getBlock('design_editor_toolbar_buttons_save'); if ($saveButtonBlock) { $saveButtonBlock->setTheme($theme)->setMode($mode)->setHasThemeAssigned($this->_customizationConfig->hasThemeAssigned()); } /** @var $saveButtonBlock \Magento\DesignEditor\Block\Adminhtml\Editor\Toolbar\Buttons\Edit */ $editButtonBlock = $this->_view->getLayout()->getBlock('design_editor_toolbar_buttons_edit'); if ($editButtonBlock) { $editButtonBlock->setTheme($editableTheme); } return $this; }
/** * 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; }
/** * Update all child themes relations * * @param \Magento\Framework\View\Design\ThemeInterface $themeModel * @return $this */ public function updateChildRelations(\Magento\Framework\View\Design\ThemeInterface $themeModel) { $parentThemeId = $themeModel->getParentId(); $this->addFieldToFilter('parent_id', ['eq' => $themeModel->getId()])->load(); /** @var $theme \Magento\Framework\View\Design\ThemeInterface */ foreach ($this->getItems() as $theme) { $theme->setParentId($parentThemeId)->save(); } return $this; }
/** * Get path to custom view configuration file * * @param \Magento\Framework\View\Design\ThemeInterface $theme * @return string|null */ public function getCustomViewConfigPath(\Magento\Framework\View\Design\ThemeInterface $theme) { $path = null; if ($theme->getId()) { $path = $this->mediaDirectoryRead->getAbsolutePath(self::DIR_NAME . '/' . $theme->getId() . '/' . $this->filename); } return $path; }
/** * Is theme assigned to specific store * * @param \Magento\Framework\View\Design\ThemeInterface $theme * @param \Magento\Store\Model\Store $store * @return bool */ protected function _isThemeAssignedToSpecificStore($theme, $store) { return $theme->getId() == $this->_getConfigurationThemeId($store); }
/** * Checks themes for changes by time * * @param \Magento\Framework\View\Design\ThemeInterface $sourceTheme * @param \Magento\Framework\View\Design\ThemeInterface $targetTheme * @return bool */ protected function _hasThemeChanged(\Magento\Framework\View\Design\ThemeInterface $sourceTheme, \Magento\Framework\View\Design\ThemeInterface $targetTheme) { $sourceChange = $this->_changeFactory->create(); $sourceChange->loadByThemeId($sourceTheme->getId()); $targetChange = $this->_changeFactory->create(); $targetChange->loadByThemeId($targetTheme->getId()); return $sourceChange->getChangeTime() !== $targetChange->getChangeTime(); }
/** * Filter out files that do not belong to a theme * * @param \Magento\Framework\View\Design\ThemeInterface $theme * @return $this */ public function addThemeFilter(\Magento\Framework\View\Design\ThemeInterface $theme) { $this->addFieldToFilter('theme_id', $theme->getId()); return $this; }
/** * Add layout links to general layout updates for themes * * @param ThemeInterface $source * @param ThemeInterface $target * @return void */ protected function _copyLayoutCustomization(ThemeInterface $source, ThemeInterface $target) { $update = $this->_updateFactory->create(); /** @var $targetUpdates \Magento\Widget\Model\Resource\Layout\Update\Collection */ $targetUpdates = $update->getCollection(); $targetUpdates->addThemeFilter($target->getId()); $targetUpdates->delete(); /** @var $sourceCollection \Magento\Widget\Model\Resource\Layout\Link\Collection */ $sourceCollection = $this->_link->getCollection(); $sourceCollection->addThemeFilter($source->getId()); /** @var $layoutLink \Magento\Widget\Model\Layout\Link */ foreach ($sourceCollection as $layoutLink) { /** @var $update \Magento\Widget\Model\Layout\Update */ $update = $this->_updateFactory->create(); $update->load($layoutLink->getLayoutUpdateId()); if ($update->getId()) { $update->setId(null); $update->save(); $layoutLink->setThemeId($target->getId()); $layoutLink->setLayoutUpdateId($update->getId()); $layoutLink->setId(null); $layoutLink->save(); } } }
/** * Generate cache identifier taking into account current area/package/theme/store * * @param string $suffix * @return string */ protected function generateCacheId($suffix = '') { return "LAYOUT_{$this->theme->getArea()}_STORE{$this->scope->getId()}_{$this->theme->getId()}{$suffix}"; }
/** * {@inheritdoc} */ public function getThemePath(\Magento\Framework\View\Design\ThemeInterface $theme) { $themePath = $theme->getThemePath(); if (!$themePath) { $themeId = $theme->getId(); if ($themeId) { $themePath = self::PUBLIC_THEME_DIR . $themeId; } else { $themePath = self::PUBLIC_VIEW_DIR; } } return $themePath; }
/** * {@inheritdoc} */ public function setTheme(\Magento\Framework\View\Design\ThemeInterface $theme) { $this->_theme = $theme; $this->setData('theme_id', $theme->getId()); $this->setData('theme_path', $theme->getThemePath()); return $this; }
/** * Add theme to shared collection * * @param \Magento\Framework\View\Design\ThemeInterface $themeModel * @return $this */ protected function _addTheme(\Magento\Framework\View\Design\ThemeInterface $themeModel) { if ($themeModel->getId()) { $this->themes[$themeModel->getId()] = $themeModel; $themePath = $themeModel->getFullPath(); if ($themePath) { $this->themesByPath[$themePath] = $themeModel; } } return $this; }