Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 protected function _prepareForm()
 {
     $form = $this->formFactory->create()->setData(['id' => 'edit_form', 'action' => $this->getUrl('*/*/save', ['id' => $this->getRequest()->getParam('id')]), 'method' => 'post', 'enctype' => 'multipart/form-data']);
     $form->setUseContainer(true);
     $this->setForm($form);
     return parent::_prepareForm();
 }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 protected function _prepareForm()
 {
     $form = $this->formFactory->create(['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]);
     $form->setUseContainer(true);
     $this->setForm($form);
     return parent::_prepareForm();
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 protected function _prepareForm()
 {
     /** @var \Mirasvit\Search\Model\Index $model */
     $model = $this->registry->registry('current_model');
     $form = $this->formFactory->create();
     $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('General Information'), 'class' => 'fieldset-wide']);
     if ($model->getId()) {
         $fieldset->addField('index_id', 'hidden', ['name' => 'id']);
     }
     $fieldset->addField('title', 'text', ['name' => 'title', 'label' => __('Title'), 'required' => true]);
     if ($model->getId()) {
         $model->setData('index_label', $model->getIndexInstance()->toString());
         $fieldset->addField('index_label', 'label', ['label' => __('Index')]);
     } else {
         $fieldset->addField('code', 'select', ['label' => __('Index'), 'name' => 'code', 'required' => true, 'values' => $this->sourceIndex->toOptionArray(true)]);
     }
     $fieldset->addField('position', 'text', ['name' => 'position', 'label' => __('Position'), 'required' => true]);
     $fieldset->addField('is_active', 'select', ['label' => __('Status'), 'name' => 'is_active', 'required' => true, 'options' => ['1' => __('Enabled'), '0' => __('Disabled')]]);
     if (!$model->getId()) {
         $model->setData('is_active', '1');
     }
     $form->setValues($model->getData());
     $this->setForm($form);
     return parent::_prepareForm();
 }
Esempio n. 5
0
 /**
  * Return Form object
  *
  * @return \Magento\Framework\Data\Form
  */
 public function getForm()
 {
     if ($this->_form === null) {
         $this->_form = $this->_formFactory->create();
         $this->_prepareForm();
     }
     return $this->_form;
 }
Esempio n. 6
0
 /**
  * @return $this
  *
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _prepareForm()
 {
     $form = $this->formFactory->create();
     $this->setForm($form);
     /** @var \Mirasvit\Blog\Model\Post $post */
     $post = $this->registry->registry('current_model');
     $fieldset = $form->addFieldset('tags_fieldset', ['class' => 'blog__post-fieldset', 'legend' => __('Author')]);
     $fieldset->addField('author_id', 'select', ['name' => 'post[author_id]', 'value' => $post->getAuthorId(), 'values' => $this->authorSource->toOptionArray()]);
     return parent::_prepareForm();
 }
Esempio n. 7
0
 /**
  * @return $this
  *
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _prepareForm()
 {
     $form = $this->formFactory->create();
     $this->setForm($form);
     /** @var \Mirasvit\Blog\Model\Post $post */
     $post = $this->registry->registry('current_model');
     $fieldset = $form->addFieldset('image_fieldset', ['class' => 'blog__post-fieldset', 'legend' => __('Featured Image')]);
     $fieldset->addField('featured_image', 'image', ['required' => false, 'name' => 'featured_image', 'value' => $post->getFeaturedImageUrl()]);
     return parent::_prepareForm();
 }
Esempio n. 8
0
 /**
  * Create the form containing the virtual rule field.
  *
  * @return \Magento\Framework\Data\Form
  */
 private function getForm()
 {
     $form = $this->formFactory->create();
     $form->setHtmlId('virtual_rule');
     $virtualRuleField = $form->addField('virtual_rule', 'text', ['name' => 'virtual_rule', 'label' => __('Virtual rule'), 'container_id' => 'virtual_rule']);
     $virtualRuleField->setValue($this->getCategory()->getVirtualRule());
     $virtualRuleRenderer = $this->getLayout()->createBlock('Smile\\ElasticsuiteCatalogRule\\Block\\Product\\Conditions');
     $virtualRuleField->setRenderer($virtualRuleRenderer);
     return $form;
 }
Esempio n. 9
0
 /**
  * @return $this
  *
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _prepareForm()
 {
     $form = $this->formFactory->create();
     $this->setForm($form);
     /** @var \Mirasvit\Blog\Model\Post $post */
     $post = $this->registry->registry('current_model');
     $fieldset = $form->addFieldset('categories_fieldset', ['class' => 'blog__post-fieldset', 'legend' => __('Categories')]);
     $collection = $this->categoryCollectionFactory->create()->addAttributeToSelect(['name']);
     $fieldset->addField('category_ids', 'checkboxes', ['name' => 'post[category_ids][]', 'value' => $post->getCategoryIds(), 'values' => $collection->toOptionArray()]);
     return parent::_prepareForm();
 }
Esempio n. 10
0
 /**
  * @param string $type
  * @dataProvider physicalTypesDataProvider
  */
 public function testProductHasWeight($type)
 {
     /** @var $currentProduct \Magento\Catalog\Model\Product */
     $currentProduct = $this->_objectManager->create('Magento\\Catalog\\Model\\Product');
     $currentProduct->setTypeInstance($this->_objectManager->create($type));
     /** @var $block \Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Weight */
     $block = $this->_objectManager->create('Magento\\Catalog\\Block\\Adminhtml\\Product\\Helper\\Form\\Weight');
     $form = $this->_formFactory->create();
     $form->setDataObject($currentProduct);
     $block->setForm($form);
     $this->assertNotRegExp('/value="0".*checked="checked"/', $block->getElementHtml(), '"Does this have a weight" is set to "No" for physical products');
 }
Esempio n. 11
0
 /**
  * @param string $type
  * @dataProvider physicalTypesDataProvider
  */
 public function testIsVirtualUnchecked($type)
 {
     /** @var $currentProduct \Magento\Catalog\Model\Product */
     $currentProduct = $this->_objectManager->create('Magento\\Catalog\\Model\\Product');
     $currentProduct->setTypeInstance($this->_objectManager->create($type));
     /** @var $block \Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Weight */
     $block = $this->_objectManager->create('Magento\\Catalog\\Block\\Adminhtml\\Product\\Helper\\Form\\Weight');
     $form = $this->_formFactory->create();
     $form->setDataObject($currentProduct);
     $block->setForm($form);
     $this->assertNotContains('checked="checked"', $block->getElementHtml(), 'Is Virtual checkbox is selected for physical products');
 }
Esempio n. 12
0
 /**
  * @return $this
  *
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _prepareForm()
 {
     $form = $this->formFactory->create();
     $this->setForm($form);
     /** @var \Mirasvit\Blog\Model\Post $post */
     $post = $this->registry->registry('current_model');
     $fieldset = $form->addFieldset('publish_fieldset', ['class' => 'blog__post-fieldset', 'legend' => __('Publish')]);
     $fieldset->addField('status', 'select', ['label' => __('Status'), 'name' => 'post[status]', 'value' => $post->getStatus(), 'values' => $this->status->toOptionArray()]);
     $fieldset->addField('created_at', 'date', ['label' => __('Published on'), 'name' => 'post[created_at]', 'value' => $post->getCreatedAt(), 'date_format' => 'MMM d, y', 'time_format' => 'h:mm a']);
     $fieldset->addField('is_pinned', 'checkbox', ['label' => __('Pin post at the top'), 'name' => 'post[is_pinned]', 'value' => 1, 'checked' => $post->getIsPinned()]);
     return parent::_prepareForm();
 }
Esempio n. 13
0
 /**
  * @return $this
  *
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _prepareForm()
 {
     $form = $this->formFactory->create();
     $this->setForm($form);
     /** @var \Mirasvit\Blog\Model\Category $category */
     $category = $this->registry->registry('current_model');
     $fieldset = $form->addFieldset('edit_fieldset', ['legend' => __('Search Engine Optimization')]);
     $fieldset->addField('url_key', 'text', ['label' => __('URL Key'), 'name' => 'url_key', 'value' => $category->getUrlKey()]);
     $fieldset->addField('meta_title', 'text', ['label' => __('Meta Title'), 'name' => 'meta_title', 'value' => $category->getMetaTitle()]);
     $fieldset->addField('meta_description', 'textarea', ['label' => __('Meta Description'), 'name' => 'meta_description', 'value' => $category->getMetaDescription()]);
     $fieldset->addField('meta_keywords', 'textarea', ['label' => __('Meta Keywords'), 'name' => 'meta_keywords', 'value' => $category->getMetaKeywords()]);
     return parent::_prepareForm();
 }
Esempio n. 14
0
 /**
  * @return $this
  *
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _prepareForm()
 {
     $form = $this->formFactory->create();
     $this->setForm($form);
     /** @var \Mirasvit\Blog\Model\Post $post */
     $post = $this->registry->registry('current_model');
     $fieldset = $form->addFieldset('edit_fieldset', ['class' => 'blog__post-fieldset']);
     $fieldset->addField('meta_title', 'text', ['label' => __('Meta Title'), 'name' => 'post[meta_title]', 'value' => $post->getMetaTitle()]);
     $fieldset->addField('meta_description', 'textarea', ['label' => __('Meta Description'), 'name' => 'post[meta_description]', 'value' => $post->getMetaDescription()]);
     $fieldset->addField('meta_keywords', 'textarea', ['label' => __('Meta Keywords'), 'name' => 'post[meta_keywords]', 'value' => $post->getMetaKeywords()]);
     $fieldset->addField('url_key', 'text', ['label' => __('URL Key'), 'name' => 'post[url_key]', 'value' => $post->getUrlKey()]);
     return parent::_prepareForm();
 }
Esempio n. 15
0
 /**
  * Render the chooser HTML
  * Target element should be set.
  *
  * @return string
  */
 protected function _toHtml()
 {
     if (empty($this->_targetElementId)) {
         return '';
     }
     $idSuffix = $this->mathRandom->getUniqueHash();
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create();
     $dateFields = array('from' => __('From'), 'to' => __('To'));
     foreach ($dateFields as $key => $label) {
         $form->addField("{$key}_{$idSuffix}", 'date', array('format' => \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT, 'label' => $label, 'image' => $this->getViewFileUrl('images/grid-cal.gif'), 'onchange' => "dateTimeChoose_{$idSuffix}()", 'value' => $this->_rangeValues[$key]));
     }
     return $form->toHtml() . "<script type=\"text/javascript\">\n            dateTimeChoose_{$idSuffix} = function() {\n                \$('{$this->_targetElementId}').value = " . "\$('from_{$idSuffix}').value + '{$this->_rangeDelimiter}' + \$('to_{$idSuffix}').value;\n            };\n            </script>";
 }
Esempio n. 16
0
 /**
  * @return $this
  *
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _prepareForm()
 {
     $form = $this->formFactory->create()->setData(['id' => 'edit_form', 'action' => $this->getUrl('*/*/save', ['id' => $this->getRequest()->getParam('id')]), 'method' => 'post', 'enctype' => 'multipart/form-data']);
     $form->setUseContainer(true);
     $this->setForm($form);
     $this->setForm($form);
     /** @var \Mirasvit\Blog\Model\Author $author */
     $author = $this->registry->registry('current_model');
     $fieldset = $form->addFieldset('edit_fieldset', ['legend' => __('Author Information')]);
     if ($author->getId()) {
         $fieldset->addField('user_id', 'hidden', ['name' => 'user_id', 'value' => $author->getId()]);
     }
     $fieldset->addField('display_name', 'text', ['label' => __('Display Name'), 'name' => 'display_name', 'value' => $author->getDisplayName(), 'required' => true]);
     $fieldset->addField('bio', 'textarea', ['label' => __('Biographical Info'), 'name' => 'bio', 'value' => $author->getBio(), 'required' => false]);
     return parent::_prepareForm();
 }
Esempio n. 17
0
 /**
  * @return $this
  *
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _prepareForm()
 {
     $form = $this->formFactory->create();
     $this->setForm($form);
     /** @var \Mirasvit\Blog\Model\Post $post */
     $post = $this->registry->registry('current_model');
     $fieldset = $form->addFieldset('edit_fieldset', ['class' => 'blog__post-fieldset']);
     if ($post->getId()) {
         $fieldset->addField('entity_id', 'hidden', ['name' => 'post[entity_id]', 'value' => $post->getId()]);
     }
     $fieldset->addField('name', 'text', ['label' => __('Title'), 'name' => 'post[name]', 'value' => $post->getName(), 'required' => true]);
     $editorConfig = $this->wysiwygConfig->getConfig(['tab_id' => $this->getTabId()]);
     $fieldset->addField('content', 'editor', ['name' => 'post[content]', 'value' => $post->getContent(), 'wysiwyg' => true, 'style' => 'height:35em', 'config' => $editorConfig]);
     $fieldset->addField('short_content', 'editor', ['label' => __('Excerpt'), 'name' => 'post[short_content]', 'value' => $post->getShortContent(), 'wysiwyg' => true, 'style' => 'height:5em', 'config' => $editorConfig]);
     return parent::_prepareForm();
 }
Esempio n. 18
0
 /**
  * Rule form getter
  *
  * @return \Magento\Framework\Data\Form
  */
 public function getForm()
 {
     if (!$this->_form) {
         $this->_form = $this->_formFactory->create();
     }
     return $this->_form;
 }
Esempio n. 19
0
 /**
  * {@inheritdoc}
  */
 protected function _prepareForm()
 {
     $form = $this->formFactory->create();
     $form->setHtmlIdPrefix('properties_');
     $model = $this->registry->registry('current_model');
     if ($model->getId()) {
         foreach ($model->getIndexInstance()->getFieldsets() as $class) {
             $fieldset = $this->objectManager->create($class);
             $fieldset->setId($class)->setLegend('Additional Options')->setIndex($model);
             $form->addElement($fieldset);
         }
     }
     $form->setValues($model->getData());
     $this->setForm($form);
     return parent::_prepareForm();
 }
 /**
  * @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);
 }
Esempio n. 21
0
 public function testCreate()
 {
     $className = 'Magento\\Framework\\Data\\Form';
     $formMock = $this->getMock($className, [], [], '', false);
     $this->_objectManagerMock->expects($this->once())->method('create')->with($className)->will($this->returnValue($formMock));
     $formFactory = new FormFactory($this->_objectManagerMock, $className);
     $this->assertSame($formMock, $formFactory->create());
 }
Esempio n. 22
0
 /**
  * @return $this
  *
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _prepareForm()
 {
     $form = $this->formFactory->create();
     $this->setForm($form);
     /** @var \Mirasvit\Blog\Model\Category $category */
     $category = $this->registry->registry('current_model');
     $fieldset = $form->addFieldset('edit_fieldset', ['legend' => __('General Information')]);
     if ($category->getId()) {
         $fieldset->addField('entity_id', 'hidden', ['name' => 'entity_id', 'value' => $category->getId()]);
     }
     $fieldset->addField('name', 'text', ['label' => __('Title'), 'name' => 'name', 'value' => $category->getName(), 'required' => true]);
     if ($category->getId() != 1) {
         $categories = $this->categoryCollectionFactory->create()->addAttributeToSelect('name')->toOptionArray();
         $fieldset->addField('parent_id', 'radios', ['label' => __('Parent Category'), 'name' => 'parent_id', 'value' => $category->getParentId() ? $category->getParentId() : 1, 'values' => $categories, 'required' => true]);
     }
     $fieldset->addField('status', 'select', ['label' => __('Status'), 'name' => 'status', 'value' => $category->getStatus(), 'values' => ['0' => __('Disabled'), '1' => __('Enabled')]]);
     return parent::_prepareForm();
 }
Esempio n. 23
0
 /**
  * @param \Magento\Backend\Block\Template\Context $context
  * @param \Magento\GoogleOptimizer\Helper\Data $helperData
  * @param \Magento\Framework\Registry $registry
  * @param \Magento\GoogleOptimizer\Helper\Code $codeHelper
  * @param \Magento\GoogleOptimizer\Helper\Form $formHelper
  * @param \Magento\Framework\Data\FormFactory $formFactory
  * @param array $data
  */
 public function __construct(\Magento\Backend\Block\Template\Context $context, \Magento\GoogleOptimizer\Helper\Data $helperData, \Magento\Framework\Registry $registry, \Magento\GoogleOptimizer\Helper\Code $codeHelper, \Magento\GoogleOptimizer\Helper\Form $formHelper, \Magento\Framework\Data\FormFactory $formFactory, array $data = [])
 {
     parent::__construct($context, $data);
     $this->_helperData = $helperData;
     $this->_registry = $registry;
     $this->_codeHelper = $codeHelper;
     $this->_formHelper = $formHelper;
     $this->setForm($formFactory->create());
 }
Esempio n. 24
0
 /**
  * Redirect via HTML form submission
  *
  * @return string
  */
 public function getHtmlFormRedirect()
 {
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->formFactory->create();
     $form->setAction($this->getTargetURL())->setId($this->getFormId())->setName($this->getFormId())->setAttr('data-auto-submit', 'true')->setMethod($this->getFormMethod())->setUseContainer(true);
     foreach ($this->_getFormFields() as $field => $value) {
         $form->addField($field, 'hidden', ['name' => $field, 'value' => $value]);
     }
     return $form->toHtml();
 }
Esempio n. 25
0
 /**
  * @return string
  */
 protected function _toHtml()
 {
     $standard = $this->_paypalStandardFactory->create();
     $form = $this->_formFactory->create();
     $form->setAction($standard->getConfig()->getPaypalUrl())->setId('paypal_standard_checkout')->setName('paypal_standard_checkout')->setMethod('POST')->setUseContainer(true);
     foreach ($standard->getStandardCheckoutFormFields() as $field => $value) {
         $form->addField($field, 'hidden', array('name' => $field, 'value' => $value));
     }
     $idSuffix = $this->mathRandom->getUniqueHash();
     $submitButton = $this->_elementFactory->create('submit', array('data' => array('value' => __('Click here if you are not redirected within 10 seconds.'))));
     $id = "submit_to_paypal_button_{$idSuffix}";
     $submitButton->setId($id);
     $form->addElement($submitButton);
     $html = '<html><body>';
     $html .= __('You will be redirected to the PayPal website in a few seconds.');
     $html .= $form->toHtml();
     $html .= '<script type="text/javascript">document.getElementById("paypal_standard_checkout").submit();';
     $html .= '</script></body></html>';
     return $html;
 }
Esempio n. 26
0
 /**
  * {@inheritdoc}
  */
 protected function _prepareForm()
 {
     $model = $this->registry->registry('current_model');
     $form = $this->formFactory->create(['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]);
     $fieldset = $form->addFieldset('base_fieldset', []);
     if ($model->getId()) {
         $fieldset->addField('stopword_id', 'hidden', ['name' => 'id']);
     }
     $fieldset->addField('term', 'text', ['name' => 'term', 'label' => __('Stopword'), 'required' => true]);
     if (!$this->storeManager->isSingleStoreMode()) {
         $field = $fieldset->addField('store_id', 'select', ['label' => __('Store'), 'title' => __('Store'), 'values' => $this->systemStore->getStoreValuesForForm(), 'name' => 'store_id', 'required' => true]);
         $renderer = $this->getLayout()->createBlock('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset\\Element');
         $field->setRenderer($renderer);
     } else {
         $fieldset->addField('store_id', 'hidden', ['name' => 'store_id', 'value' => $this->storeManager->getStore(true)->getId()]);
     }
     $form->setValues($model->getData());
     $form->setUseContainer(true);
     $this->setForm($form);
     return parent::_prepareForm();
 }
Esempio n. 27
0
 /**
  * Initialize form
  *
  * @return $this
  */
 public function initForm()
 {
     $this->_initObjects();
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create();
     /** @var $section \Magento\Backend\Model\Config\Structure\Element\Section */
     $section = $this->_configStructure->getElement($this->getSectionCode());
     if ($section && $section->isVisible($this->getWebsiteCode(), $this->getStoreCode())) {
         foreach ($section->getChildren() as $group) {
             $this->_initGroup($group, $section, $form);
         }
     }
     $this->setForm($form);
     return $this;
 }
Esempio n. 28
0
 /**
  * @covers \Magento\Config\Block\System\Config\Form::initFields
  * @param string $fieldId uses the test_field_use_config field if true
  * @param bool $isConfigDataEmpty if the config data array should be empty or not
  * @param string $configDataValue Value that the field path should be set to in the config data
  * @param int $valueSelCtr Number of time that value is selected
  * @dataProvider initFieldsUseConfigPathDataProvider
  * @magentoConfigFixture default/test_config_section/test_group_config_node/test_field_value config value
  */
 public function testInitFieldsUseConfigPath($fieldId, $isConfigDataEmpty, $configDataValue, $valueSelCtr = 1)
 {
     $this->_setupFieldsInheritCheckbox($fieldId, $isConfigDataEmpty, $configDataValue);
     \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\Config\\ScopeInterface')->setCurrentScope(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
     $form = $this->_formFactory->create();
     $fieldset = $form->addFieldset($this->_section->getId() . '_' . $this->_group->getId(), []);
     /* @TODO Eliminate stub by proper mock / config fixture usage */
     /** @var $block \Magento\Config\Block\System\Config\FormStub */
     $block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\LayoutInterface')->createBlock('Magento\\Config\\Block\\System\\Config\\FormStub');
     $block->setScope(\Magento\Config\Block\System\Config\Form::SCOPE_DEFAULT);
     $block->setStubConfigData($this->_configData);
     $block->initFields($fieldset, $this->_group, $this->_section);
     $fieldsetSel = 'fieldset';
     $valueSel = sprintf('input#%s_%s_%s', $this->_section->getId(), $this->_group->getId(), $this->_field->getId());
     $fieldsetHtml = $fieldset->getElementHtml();
     $this->assertSelectCount($fieldsetSel, true, $fieldsetHtml, 'Fieldset HTML is invalid');
     $this->assertSelectCount($valueSel, $valueSelCtr, $fieldsetHtml, 'Field input should appear ' . $valueSelCtr . ' times in fieldset HTML');
 }
Esempio n. 29
0
 /**
  * Instantiate form and fields
  *
  * @return \Magento\Framework\Data\Form
  */
 protected function _prepareForm()
 {
     $form = $this->_formFactory->create();
     $form->setFieldsetRenderer($this->getLayout()->createBlock('Magento\\Backend\\Block\\Widget\\Form\\Renderer\\Fieldset'));
     $form->setFieldsetElementRenderer($this->getLayout()->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Form\\Renderer\\Fieldset\\Element'));
     /**
      * if there is a parent element defined, it will be replaced by a hidden element with the same name
      * and overridden by the form elements
      * It is needed to maintain HTML consistency of the parent element's form
      */
     if ($this->_parentElement) {
         $form->setHtmlIdPrefix($this->_parentElement->getHtmlId())->setFieldNameSuffix($this->_parentElement->getName());
         $form->addField('', 'hidden', array('name' => ''));
     }
     $noYes = array(__('No'), __('Yes'));
     // schedule
     $schedule = $form->addFieldset('schedule_fieldset', array('legend' => __('Schedule'), 'disabled' => $this->_isReadOnly));
     $schedule->addField('start_date_is_editable', 'select', array('name' => 'start_date_is_editable', 'label' => __('Customer Can Define Start Date'), 'comment' => __('Select whether buyer can define the date when billing for the payment begins.'), 'options' => $noYes, 'disabled' => $this->_isReadOnly));
     $this->_addField($schedule, 'schedule_description');
     $this->_addField($schedule, 'suspension_threshold');
     $this->_addField($schedule, 'bill_failed_later', array('options' => $noYes), 'select');
     // billing
     $billing = $form->addFieldset('billing_fieldset', array('legend' => __('Billing'), 'disabled' => $this->_isReadOnly));
     $this->_addField($billing, 'period_unit', array('options' => $this->_getPeriodUnitOptions(__('-- Please Select --'))), 'select');
     $this->_addField($billing, 'period_frequency');
     $this->_addField($billing, 'period_max_cycles');
     // trial
     $trial = $form->addFieldset('trial_fieldset', array('legend' => __('Trial Period'), 'disabled' => $this->_isReadOnly));
     $this->_addField($trial, 'trial_period_unit', array('options' => $this->_getPeriodUnitOptions(__('-- Not Selected --'))), 'select');
     $this->_addField($trial, 'trial_period_frequency');
     $this->_addField($trial, 'trial_period_max_cycles');
     $this->_addField($trial, 'trial_billing_amount');
     // initial fees
     $initial = $form->addFieldset('initial_fieldset', array('legend' => __('Initial Fees'), 'disabled' => $this->_isReadOnly));
     $this->_addField($initial, 'init_amount');
     $this->_addField($initial, 'init_may_fail', array('options' => $noYes), 'select');
     return $form;
 }
Esempio n. 30
0
 /**
  * @param string $switchAttributeCode
  * @return \Magento\Framework\Data\Form\Element\Select
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function getExtendedElement($switchAttributeCode)
 {
     $form = $this->formFactory->create();
     return $form->addField($switchAttributeCode, 'select', ['name' => "product[{$switchAttributeCode}]", 'values' => $this->getOptions(), 'value' => $switchAttributeCode, 'class' => 'required-entry next-toinput', 'no_span' => true, 'disabled' => $this->isDisabledField(), 'value' => $this->getProduct()->getData($switchAttributeCode)]);
 }