Пример #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;
 }