Beispiel #1
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();
 }
Beispiel #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;
 }
 public function testToHtml()
 {
     $fieldSet = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Fieldset', [], [], '', false);
     $form = $this->getMock('Magento\\Framework\\Data\\Form', [], [], '', false);
     $attributeModel = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], [], '', false);
     $entityType = $this->getMock('Magento\\Eav\\Model\\Entity\\Type', [], [], '', false);
     $formElement = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Text', ['setDisabled'], [], '', false);
     $directoryReadInterface = $this->getMock('\\Magento\\Framework\\Filesystem\\Directory\\ReadInterface');
     $this->registry->expects($this->any())->method('registry')->with('entity_attribute')->willReturn($attributeModel);
     $this->formFactory->expects($this->any())->method('create')->willReturn($form);
     $form->expects($this->any())->method('addFieldset')->willReturn($fieldSet);
     $form->expects($this->any())->method('getElement')->willReturn($formElement);
     $fieldSet->expects($this->any())->method('addField')->willReturnSelf();
     $attributeModel->expects($this->any())->method('getDefaultValue')->willReturn('default_value');
     $attributeModel->expects($this->any())->method('setDisabled')->willReturnSelf();
     $attributeModel->expects($this->any())->method('getId')->willReturn(1);
     $attributeModel->expects($this->any())->method('getEntityType')->willReturn($entityType);
     $attributeModel->expects($this->any())->method('getIsUserDefined')->willReturn(false);
     $attributeModel->expects($this->any())->method('getAttributeCode')->willReturn('attribute_code');
     $this->localeDate->expects($this->any())->method('getDateFormat')->willReturn('mm/dd/yy');
     $entityType->expects($this->any())->method('getEntityTypeCode')->willReturn('entity_type_code');
     $this->eavData->expects($this->any())->method('getFrontendClasses')->willReturn([]);
     $formElement->expects($this->exactly(3))->method('setDisabled')->willReturnSelf();
     $this->yesNo->expects($this->any())->method('toOptionArray')->willReturn(['yes', 'no']);
     $this->filesystem->expects($this->any())->method('getDirectoryRead')->willReturn($directoryReadInterface);
     $directoryReadInterface->expects($this->any())->method('getRelativePath')->willReturn('relative_path');
     $this->block->setData(['action' => 'save']);
     $this->block->toHtml();
 }
Beispiel #4
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();
 }
Beispiel #5
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();
 }
 /**
  * @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);
 }
 /**
  * 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;
 }
 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());
 }
 /**
  * @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());
 }
 public function testBeforeToHtml()
 {
     $formMock = $this->getMockBuilder('Magento\\Framework\\Data\\Form')->disableOriginalConstructor()->setMethods([])->getMock();
     $fieldsetMock = $this->getMockBuilder('Magento\\Framework\\Data\\Form\\Element\\Fieldset')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->formFactoryMock->expects($this->any())->method('create')->willReturn($formMock);
     $formMock->expects($this->any())->method('addFieldSet')->willReturn($fieldsetMock);
     $fieldsetMock->expects($this->exactly(4))->method('addField')->withConsecutive(['role_name'], ['role_id'], ['in_role_user'], ['in_role_user_old']);
     $this->assertInstanceOf('Magento\\User\\Block\\Role\\Tab\\Info', $this->model->_beforeToHtml());
 }
Beispiel #11
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;
 }
Beispiel #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('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();
 }
Beispiel #13
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();
 }
 protected function setUp()
 {
     parent::setUp();
     $this->formFactoryMock = $this->getMockBuilder(FormFactory::class)->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->formMock = $this->getMockBuilder(Form::class)->disableOriginalConstructor()->getMock();
     $this->wysiwygConfig = $this->getMockBuilder(ConfigInterface::class)->getMockForAbstractClass();
     $this->editorMock = $this->getMockBuilder(Editor::class)->disableOriginalConstructor()->getMock();
     $this->formFactoryMock->expects($this->any())->method('create')->willReturn($this->formMock);
     $this->formMock->expects($this->once())->method('addField')->willReturn($this->editorMock);
     $this->editorMock->expects($this->once())->method('getElementHtml');
 }
Beispiel #15
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();
 }
 /**
  * @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');
 }
Beispiel #17
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');
 }
Beispiel #18
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();
 }
Beispiel #19
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();
 }
 public function testGetExtendedElement()
 {
     $switchAttributeCode = 'test_code';
     $form = $this->getMockBuilder(\Magento\Framework\Data\Form::class)->disableOriginalConstructor()->getMock();
     $and = new \PHPUnit_Framework_Constraint_And();
     $and->setConstraints([new \PHPUnit_Framework_Constraint_ArrayHasKey('value')]);
     $form->expects($this->once())->method('addField')->with($switchAttributeCode, 'select', $and);
     $this->formFactory->expects($this->once())->method('create')->with()->will($this->returnValue($form));
     $product = $this->getProduct();
     $product->expects($this->once())->method('getData')->with($switchAttributeCode)->will($this->returnValue(123));
     $this->object->setIsDisabledField(true);
     $this->object->getExtendedElement($switchAttributeCode);
 }
Beispiel #21
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();
 }
Beispiel #22
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>";
 }
Beispiel #23
0
 /**
  * Rule form getter
  *
  * @return \Magento\Framework\Data\Form
  */
 public function getForm()
 {
     if (!$this->_form) {
         $this->_form = $this->_formFactory->create();
     }
     return $this->_form;
 }
Beispiel #24
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();
 }
Beispiel #25
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();
 }
Beispiel #26
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();
 }
Beispiel #27
0
 public function testToHtmlWithoutRatingData()
 {
     $this->registry->expects($this->any())->method('registry')->will($this->returnValue(false));
     $this->systemStore->expects($this->any())->method('getStoreCollection')->will($this->returnValue(['0' => $this->store]));
     $this->formFactory->expects($this->any())->method('create')->will($this->returnValue($this->form));
     $this->viewFileSystem->expects($this->any())->method('getTemplateFileName')->will($this->returnValue('template_file_name.html'));
     $this->fileSystem->expects($this->any())->method('getDirectoryRead')->will($this->returnValue($this->directoryReadInterface));
     $this->block->toHtml();
 }
Beispiel #28
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();
 }
Beispiel #29
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();
 }
Beispiel #30
0
 public function testAddErrorMessageWhenProductWithoutStores()
 {
     $form = $this->getMock('Magento\\Framework\\Data\\Form', [], [], '', false);
     $form->expects($this->any())->method('getElement')->will($this->returnValue($this->getMockForAbstractClass('\\Magento\\Framework\\Data\\Form\\Element\\AbstractElement', [], '', false)));
     $this->formFactory->expects($this->once())->method('create')->will($this->returnValue($form));
     $fieldset = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Fieldset', [], [], '', false);
     $form->expects($this->once())->method('addFieldset')->will($this->returnValue($fieldset));
     $storeElement = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\AbstractElement', ['setAfterElementHtml', 'setValues'], [], '', false);
     $fieldset->expects($this->at(2))->method('addField')->with('store_id', 'select', ['label' => 'Store', 'title' => 'Store', 'name' => 'store_id', 'required' => true, 'value' => 0])->willReturn($storeElement);
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
     $product->expects($this->any())->method('getId')->willReturn('product_id');
     $product->expects($this->once())->method('getStoreIds')->willReturn([]);
     $this->productFactory->expects($this->once())->method('create')->willReturn($product);
     $this->categoryFactory->expects($this->once())->method('create')->willReturn($this->getMock('Magento\\Catalog\\Model\\Category', [], [], '', false));
     $storeElement->expects($this->once())->method('setAfterElementHtml');
     $storeElement->expects($this->once())->method('setValues')->with([]);
     $this->layout->expects($this->once())->method('createBlock')->willReturn($this->getMock('Magento\\Framework\\Data\\Form\\Element\\Renderer\\RendererInterface'));
     $this->form->toHtml();
 }