/** * @param ContextInterface $context * @param FormFactory $formFactory * @param ConfigInterface $wysiwygConfig * @param array $components * @param array $data * @param array $config */ public function __construct(ContextInterface $context, FormFactory $formFactory, ConfigInterface $wysiwygConfig, array $components = [], array $data = [], array $config = []) { $wysiwygConfigData = isset($config['wysiwygConfigData']) ? $config['wysiwygConfigData'] : []; $this->form = $formFactory->create(); $this->editor = $this->form->addField($context->getNamespace() . '_' . $data['name'], 'Magento\\Framework\\Data\\Form\\Element\\Editor', ['force_load' => true, 'rows' => 20, 'name' => $data['name'], 'config' => $wysiwygConfig->getConfig($wysiwygConfigData), 'wysiwyg' => isset($config['wysiwyg']) ? $config['wysiwyg'] : null]); $data['config']['content'] = $this->editor->getElementHtml(); parent::__construct($context, $components, $data); }
/** * Initialize form elements * * @param Configuration $controlsConfig * @param Form $form * @return $this */ protected function _initFormElements($controlsConfig, $form) { $hintMessage = __('Please enter values for height and width.' . ' Use the chain icon if you want height and width to match.' . ' Be sure to see how it looks in your store.' . ' You may need to update your custom CSS file.'); $form->addField('information_hint', 'note', ['after_element_html' => '<p class="note">' . $hintMessage . '</p>']); $whiteBorder = $controlsConfig->getControlData('product_image_border'); if ($whiteBorder) { $this->_addWhiteBorderElement($whiteBorder); } $controls = $controlsConfig->getAllControlsData(); foreach ($controls as $name => $control) { if ($control['type'] != 'image-sizing') { continue; } $this->_addImageSizeFieldset($name, $control); } $fieldset = $form->addFieldset('save_image_sizing_fieldset', ['name' => 'save_image_sizing_fieldset', 'fieldset_type' => 'field', 'class' => 'save_image_sizing']); $this->_addElementTypes($fieldset); if ($whiteBorder || $controls) { $fieldset->addField('save_image_sizing', 'button_button', ['name' => 'save_image_sizing', 'title' => __('Update'), 'value' => __('Update'), 'data-mage-init' => $this->escapeHtml(json_encode(['button' => ['event' => 'saveForm', 'target' => 'body']]))]); } return $this; }
/** * Add column elements to form * * @param Form $form * @param string $tab * @return array */ protected function _initColumns($form, $tab) { /** @var $columnLeft \Magento\DesignEditor\Block\Adminhtml\Editor\Form\Element\Column */ $columnLeft = $form->addField('column-left-' . $tab, 'column', []); $columnLeft->setRendererFactory($this->_rendererFactory)->setElementsFactory($this->_elementsFactory); /** @var $columnMiddle \Magento\DesignEditor\Block\Adminhtml\Editor\Form\Element\Column */ $columnMiddle = $form->addField('column-middle-' . $tab, 'column', []); $columnMiddle->setRendererFactory($this->_rendererFactory)->setElementsFactory($this->_elementsFactory); /** @var $columnRight \Magento\DesignEditor\Block\Adminhtml\Editor\Form\Element\Column */ $columnRight = $form->addField('column-right-' . $tab, 'column', []); $columnRight->setRendererFactory($this->_rendererFactory)->setElementsFactory($this->_elementsFactory); $columns = ['left' => $columnLeft, 'middle' => $columnMiddle, 'right' => $columnRight]; return $columns; }
/** * Add a field to the form or fieldset * Form and fieldset have same abstract * * @param \Magento\Framework\Data\Form|\Magento\Framework\Data\Form\Element\Fieldset $formOrFieldset * @param string $elementName * @param array $options * @param string $type * @return \Magento\Framework\Data\Form\Element\AbstractElement */ protected function _addField($formOrFieldset, $elementName, $options = array(), $type = 'text') { $options = array_merge($options, array('name' => $elementName, 'label' => $this->_recurringPaymentFields->getFieldLabel($elementName), 'note' => $this->_recurringPaymentFields->getFieldComment($elementName), 'disabled' => $this->_isReadOnly)); if (in_array($elementName, array('period_unit', 'period_frequency'))) { $options['required'] = true; } return $formOrFieldset->addField($elementName, $type, $options); }