Exemplo n.º 1
0
 /**
  * Add theme fieldset
  *
  * @param \Magento\Framework\Data\Form $form
  * @param array $formData
  * @param ThemeInterface $theme
  * @return $this
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _addThemeFieldset($form, $formData, ThemeInterface $theme)
 {
     $themeFieldset = $form->addFieldset('theme', ['legend' => __('Theme Settings')]);
     $this->_addElementTypes($themeFieldset);
     if (isset($formData['theme_id'])) {
         $themeFieldset->addField('theme_id', 'hidden', ['name' => 'theme_id']);
     }
     /** @var \Magento\Theme\Model\Theme\Collection $themesCollections */
     $themesCollections = $this->_objectManager->create('Magento\\Theme\\Model\\Theme\\Collection');
     /** @var \Magento\Framework\Json\Helper\Data $helper */
     $helper = $this->_objectManager->get('Magento\\Framework\\Json\\Helper\\Data');
     $onChangeScript = sprintf('parentThemeOnChange(this.value, %s)', str_replace('"', '\'', $helper->jsonEncode($this->_getDefaultsInherited($themesCollections->addDefaultPattern()))));
     /** @var ThemeInterface $parentTheme */
     $parentTheme = $this->_objectManager->create('Magento\\Framework\\View\\Design\\ThemeInterface');
     if (!empty($formData['parent_id'])) {
         $parentTheme->load($formData['parent_id']);
     }
     if ($this->_getCurrentTheme()->isObjectNew()) {
         $themeFieldset->addField('parent_id', 'select', ['label' => __('Parent Theme'), 'title' => __('Parent Theme'), 'name' => 'parent_id', 'values' => $themesCollections->toOptionArray(!$parentTheme->getId()), 'required' => true, 'class' => 'no-changes', 'onchange' => $onChangeScript]);
     } elseif (!empty($formData['parent_id'])) {
         $themeFieldset->addField('parent_title', 'note', ['label' => __('Parent Theme'), 'title' => __('Parent Theme'), 'name' => 'parent_title', 'text' => $parentTheme->getId() ? $parentTheme->getThemeTitle() : '']);
     }
     if (!empty($formData['theme_path'])) {
         $themeFieldset->addField('theme_path', 'label', ['label' => __('Theme Path'), 'title' => __('Theme Path'), 'name' => 'theme_code']);
     }
     $themeFieldset->addField('theme_title', $this->_getFieldTextType(), ['label' => __('Theme Title'), 'title' => __('Theme Title'), 'name' => 'theme_title', 'required' => $this->_isFieldAttrRequired()]);
     if ($this->_isThemeEditable) {
         $themeFieldset->addField('preview_image', 'image', ['label' => __('Theme Preview Image'), 'title' => __('Theme Preview Image'), 'name' => 'preview', 'required' => false, 'note' => $this->_getPreviewImageNote(), 'theme' => $theme]);
     } elseif ($theme->hasPreviewImage()) {
         $themeFieldset->addField('preview_image', 'note', ['label' => __('Theme Preview Image'), 'title' => __('Theme Preview Image'), 'name' => 'preview', 'after_element_html' => '<a href="' . $theme->getThemeImage()->getPreviewImageUrl() . '" onclick="imagePreview(\'theme_preview_image\'); return false;">' . '<img width="50" src="' . $theme->getThemeImage()->getPreviewImageUrl() . '" id="theme_preview_image" /></a>']);
     }
     return $this;
 }
Exemplo n.º 2
0
 /**
  * Save preview image for theme
  *
  * @param ThemeInterface $theme
  * @return $this
  */
 protected function _savePreviewImage(ThemeInterface $theme)
 {
     $themeDirectory = $theme->getCustomization()->getThemeFilesPath();
     if (!$theme->getPreviewImage() || !$themeDirectory) {
         return $this;
     }
     $imagePath = $themeDirectory . '/' . $theme->getPreviewImage();
     if (0 === strpos($imagePath, $themeDirectory)) {
         $theme->getThemeImage()->createPreviewImage($imagePath);
     }
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Create preview image duplicate
  *
  * @param ThemeInterface $theme
  * @return bool
  */
 public function createPreviewImageCopy(ThemeInterface $theme)
 {
     $previewDir = $this->themeImagePath->getImagePreviewDirectory();
     $sourcePath = $theme->getThemeImage()->getPreviewImagePath();
     $sourceRelativePath = $this->rootDirectory->getRelativePath($sourcePath);
     if (!$theme->getPreviewImage() && !$this->mediaDirectory->isExist($sourceRelativePath)) {
         return false;
     }
     $isCopied = false;
     try {
         $destinationFileName = \Magento\Framework\File\Uploader::getNewFileName($sourcePath);
         $targetRelativePath = $this->mediaDirectory->getRelativePath($previewDir . '/' . $destinationFileName);
         $isCopied = $this->rootDirectory->copyFile($sourceRelativePath, $targetRelativePath, $this->mediaDirectory);
         $this->theme->setPreviewImage($destinationFileName);
     } catch (\Magento\Framework\Filesystem\FilesystemException $e) {
         $this->theme->setPreviewImage(null);
         $this->logger->critical($e);
     }
     return $isCopied;
 }