/** * Create varien data form with provided params * * @param array $data * @return Form * @throws \InvalidArgumentException */ public function create(array $data = []) { $isFilePresent = true; try { $this->_config = $this->_configFactory->create(\Magento\DesignEditor\Model\Editor\Tools\Controls\Factory::TYPE_QUICK_STYLES, $data['theme'], $data['parent_theme']); } catch (\Magento\Framework\Exception\LocalizedException $e) { $isFilePresent = false; } if (!isset($data['tab'])) { throw new \InvalidArgumentException(sprintf('Invalid controls tab "%s".', $data['tab'])); } if ($isFilePresent) { /** @var $form Form */ $form = $this->_formFactory->create(['data' => $data]); $this->_addElementTypes($form); $columns = $this->_initColumns($form, $data['tab']); $this->_populateColumns($columns, $data['tab']); } else { $form = $this->_formFactory->create(['data' => ['action' => '#']]); } if ($this->_isFormEmpty($form)) { $hintMessage = __('Sorry, but you cannot edit these theme styles.'); $form->addField($data['tab'] . '-tab-error', 'note', ['after_element_html' => '<p class="error-notice">' . $hintMessage . '</p>'], '^'); } return $form; }
/** * Test control data * * @magentoDataFixture Magento/DesignEditor/Model/_files/design/themes.php * @dataProvider getSaveDataProvider * @magentoAppIsolation enabled */ public function testSaveConfiguration($saveData, $xpathData) { $type = \Magento\DesignEditor\Model\Editor\Tools\Controls\Factory::TYPE_QUICK_STYLES; $theme = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\DesignInterface')->getDesignTheme(); $configuration = $this->_configFactory->create($type, $theme); $configuration->saveData($saveData); $this->assertFileExists($theme->getCustomization()->getCustomViewConfigPath()); $actual = new \DOMDocument(); $actual->load($theme->getCustomization()->getCustomViewConfigPath()); $domXpath = new \DOMXPath($actual); foreach ($xpathData as $xpath => $isEmpty) { if ($isEmpty) { $this->assertEmpty($domXpath->query($xpath)->item(0)); } else { $this->assertNotEmpty($domXpath->query($xpath)->item(0)); } } }
/** * Create a form element with necessary controls * * @return $this */ protected function _prepareForm() { /** @var Form $form */ $form = $this->_formFactory->create(['data' => ['action' => '#', 'method' => 'post']]); $form->setId('product_image_sizing_form'); $this->setForm($form); $form->setUseContainer(true); $form->setFieldNameSuffix('imagesizing'); $form->addType('button_button', 'Magento\\DesignEditor\\Block\\Adminhtml\\Editor\\Form\\Element\\Button'); $isFilePresent = true; try { /** @var $controlsConfig Configuration */ $controlsConfig = $this->_controlFactory->create(\Magento\DesignEditor\Model\Editor\Tools\Controls\Factory::TYPE_IMAGE_SIZING, $this->_themeContext->getStagingTheme()); } catch (\Magento\Framework\Exception $e) { $isFilePresent = false; } if ($isFilePresent) { $this->_initFormElements($controlsConfig, $form); } else { $hintMessage = __('Sorry, but you cannot resize images for this theme.'); $form->addField('imagesize-tab-error', 'note', ['after_element_html' => '<p class="error-notice">' . $hintMessage . '</p>']); } return parent::_prepareForm(); }