/** * Check a theme, it's assigned to any of store * * @param EventObserver $observer * @return void */ public function execute(EventObserver $observer) { $theme = $observer->getEvent()->getData('theme'); if ($theme instanceof \Magento\Framework\View\Design\ThemeInterface) { /** @var $theme \Magento\Framework\View\Design\ThemeInterface */ if ($this->themeConfig->isThemeAssignedToStore($theme)) { $this->eventDispatcher->dispatch('assigned_theme_changed', ['theme' => $theme]); } } }
/** * Clean related contents to a theme (before save) * * @param EventObserver $observer * @return void * @throws \Magento\Framework\Exception\LocalizedException */ public function execute(EventObserver $observer) { $theme = $observer->getEvent()->getData('theme'); if (!$theme instanceof \Magento\Framework\View\Design\ThemeInterface) { return; } /** @var $theme \Magento\Framework\View\Design\ThemeInterface */ if ($this->themeConfig->isThemeAssignedToStore($theme)) { throw new \Magento\Framework\Exception\LocalizedException(__('Theme isn\'t deletable.')); } $this->themeImageFactory->create(['theme' => $theme])->removePreviewImage(); $this->updateCollection->addThemeFilter($theme->getId())->delete(); }
/** * Create a form element with necessary controls * * @return $this */ protected function _prepareForm() { /** @var \Magento\Framework\Data\Form $form */ $form = $this->_formFactory->create(array('data' => array('action' => '#', 'method' => 'post'))); $this->setForm($form); $form->setUseContainer(true); $form->addType('js_files', 'Magento\\DesignEditor\\Block\\Adminhtml\\Editor\\Form\\Element\\Uploader'); $jsConfig = array('name' => 'js_files_uploader', 'title' => __('Select JS Files to Upload'), 'accept' => 'application/x-javascript', 'multiple' => '1'); if ($this->_customizationConfig->isThemeAssignedToStore($this->_themeContext->getEditableTheme())) { $confirmMessage = __('These JavaScript files may change the appearance of your live store(s).' . ' Are you sure you want to do this?'); $jsConfig['onclick'] = "return confirm('{$confirmMessage}');"; } $form->addField('js_files_uploader', 'js_files', $jsConfig); parent::_prepareForm(); return $this; }
/** * Check if theme is assigned to ANY store * * @return bool */ public function isAssigned() { return $this->_customizationConfig->isThemeAssignedToStore($this->_theme); }
/** * @covers \Magento\Theme\Model\Config\Customization::isThemeAssignedToStore */ public function testIsThemeAssignedToConcreteStore() { $this->designPackage->expects($this->once())->method('getConfigurationDesignTheme')->willReturn($this->getAssignedTheme()->getId()); $themeUnassigned = $this->model->isThemeAssignedToStore($this->getUnassignedTheme(), $this->getStore()); $this->assertEquals(false, $themeUnassigned); }