Exemplo n.º 1
0
 /**
  * Form post init
  *
  * @param \Magento\Framework\Data\Form $form
  * @return \Magento\UrlRedirect\Block\Cms\Page\Edit\Form
  */
 protected function _formPostInit($form)
 {
     $cmsPage = $this->_getCmsPage();
     $form->setAction($this->_adminhtmlData->getUrl('adminhtml/*/save', array('id' => $this->_getModel()->getId(), 'cms_page' => $cmsPage->getId())));
     // Fill request path and target path elements
     /** @var $requestPath \Magento\Framework\Data\Form\Element\AbstractElement */
     $requestPath = $this->getForm()->getElement('request_path');
     /** @var $targetPath \Magento\Framework\Data\Form\Element\AbstractElement */
     $targetPath = $this->getForm()->getElement('target_path');
     $model = $this->_getModel();
     /** @var $cmsPageUrlrewrite \Magento\Cms\Model\Page\Urlrewrite */
     $cmsPageUrlrewrite = $this->_urlRewriteFactory->create();
     if (!$model->getId()) {
         $sessionData = $this->_getSessionData();
         if (!isset($sessionData['request_path'])) {
             $requestPath->setValue($cmsPageUrlrewrite->generateRequestPath($cmsPage));
         }
         $targetPath->setValue($cmsPageUrlrewrite->generateTargetPath($cmsPage));
         $disablePaths = true;
     } else {
         $cmsPageUrlrewrite->load($this->_getModel()->getId(), 'url_rewrite_id');
         $disablePaths = $cmsPageUrlrewrite->getId() > 0;
     }
     if ($disablePaths) {
         $targetPath->setData('disabled', true);
     }
     return $this;
 }
Exemplo n.º 2
0
 /**
  * Prepare group specific fieldset
  *
  * @param \Magento\Framework\Data\Form $form
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _prepareStoreFieldset(\Magento\Framework\Data\Form $form)
 {
     $groupModel = $this->_coreRegistry->registry('store_data');
     $postData = $this->_coreRegistry->registry('store_post_data');
     if ($postData) {
         $groupModel->setData($postData['group']);
     }
     $fieldset = $form->addFieldset('group_fieldset', ['legend' => __('Store Information')]);
     $storeAction = $this->_coreRegistry->registry('store_action');
     if ($storeAction == 'edit' || $storeAction == 'add') {
         $websites = $this->_websiteFactory->create()->getCollection()->toOptionArray();
         $fieldset->addField('group_website_id', 'select', ['name' => 'group[website_id]', 'label' => __('Web Site'), 'value' => $groupModel->getWebsiteId(), 'values' => $websites, 'required' => true, 'disabled' => $groupModel->isReadOnly()]);
         if ($groupModel->getId() && $groupModel->getWebsite()->getDefaultGroupId() == $groupModel->getId()) {
             if ($groupModel->getWebsite()->getIsDefault() || $groupModel->getWebsite()->getGroupsCount() == 1) {
                 $form->getElement('group_website_id')->setDisabled(true);
                 $fieldset->addField('group_hidden_website_id', 'hidden', ['name' => 'group[website_id]', 'no_span' => true, 'value' => $groupModel->getWebsiteId()]);
             } else {
                 $fieldset->addField('group_original_website_id', 'hidden', ['name' => 'group[original_website_id]', 'no_span' => true, 'value' => $groupModel->getWebsiteId()]);
             }
         }
     }
     $fieldset->addField('group_name', 'text', ['name' => 'group[name]', 'label' => __('Name'), 'value' => $groupModel->getName(), 'required' => true, 'disabled' => $groupModel->isReadOnly()]);
     $categories = $this->_category->toOptionArray();
     $fieldset->addField('group_root_category_id', 'select', ['name' => 'group[root_category_id]', 'label' => __('Root Category'), 'value' => $groupModel->getRootCategoryId(), 'values' => $categories, 'required' => true, 'disabled' => $groupModel->isReadOnly()]);
     if ($this->_coreRegistry->registry('store_action') == 'edit') {
         $storeActive = 1;
         $stores = $this->_storeFactory->create()->getCollection()->addGroupFilter($groupModel->getId())->addStatusFilter($storeActive)->toOptionArray();
         $fieldset->addField('group_default_store_id', 'select', ['name' => 'group[default_store_id]', 'label' => __('Default Store View'), 'value' => $groupModel->getDefaultStoreId(), 'values' => $stores, 'required' => false, 'disabled' => $groupModel->isReadOnly()]);
     }
     $fieldset->addField('group_group_id', 'hidden', ['name' => 'group[group_id]', 'no_span' => true, 'value' => $groupModel->getId()]);
 }
Exemplo n.º 3
0
 /**
  * Prepare store specific fieldset
  *
  * @param \Magento\Framework\Data\Form $form
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _prepareStoreFieldset(\Magento\Framework\Data\Form $form)
 {
     $storeModel = $this->_coreRegistry->registry('store_data');
     $postData = $this->_coreRegistry->registry('store_post_data');
     if ($postData) {
         $storeModel->setData($postData['store']);
     }
     $fieldset = $form->addFieldset('store_fieldset', array('legend' => __('Store View Information')));
     $storeAction = $this->_coreRegistry->registry('store_action');
     if ($storeAction == 'edit' || $storeAction == 'add') {
         $fieldset->addField('store_group_id', 'select', array('name' => 'store[group_id]', 'label' => __('Store'), 'value' => $storeModel->getGroupId(), 'values' => $this->_getStoreGroups(), 'required' => true, 'disabled' => $storeModel->isReadOnly()));
         if ($storeModel->getId() && $storeModel->getGroup()->getDefaultStoreId() == $storeModel->getId()) {
             if ($storeModel->getGroup() && $storeModel->getGroup()->getStoresCount() > 1) {
                 $form->getElement('store_group_id')->setDisabled(true);
                 $fieldset->addField('store_hidden_group_id', 'hidden', array('name' => 'store[group_id]', 'no_span' => true, 'value' => $storeModel->getGroupId()));
             } else {
                 $fieldset->addField('store_original_group_id', 'hidden', array('name' => 'store[original_group_id]', 'no_span' => true, 'value' => $storeModel->getGroupId()));
             }
         }
     }
     $fieldset->addField('store_name', 'text', array('name' => 'store[name]', 'label' => __('Name'), 'value' => $storeModel->getName(), 'required' => true, 'disabled' => $storeModel->isReadOnly()));
     $fieldset->addField('store_code', 'text', array('name' => 'store[code]', 'label' => __('Code'), 'value' => $storeModel->getCode(), 'required' => true, 'disabled' => $storeModel->isReadOnly()));
     $fieldset->addField('store_is_active', 'select', array('name' => 'store[is_active]', 'label' => __('Status'), 'value' => $storeModel->getIsActive(), 'options' => array(0 => __('Disabled'), 1 => __('Enabled')), 'required' => true, 'disabled' => $storeModel->isReadOnly()));
     $fieldset->addField('store_sort_order', 'text', array('name' => 'store[sort_order]', 'label' => __('Sort Order'), 'value' => $storeModel->getSortOrder(), 'required' => false, 'disabled' => $storeModel->isReadOnly()));
     $fieldset->addField('store_is_default', 'hidden', array('name' => 'store[is_default]', 'no_span' => true, 'value' => $storeModel->getIsDefault()));
     $fieldset->addField('store_store_id', 'hidden', array('name' => 'store[store_id]', 'no_span' => true, 'value' => $storeModel->getId(), 'disabled' => $storeModel->isReadOnly()));
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
0
 /**
  * Prepare form
  *
  * @param DataForm $form
  * @param ModelCode|null $experimentCodeModel
  * @param string $formName
  * @return void
  */
 public function addGoogleoptimizerFields(DataForm $form, ModelCode $experimentCodeModel = null, $formName = '')
 {
     $fieldset = $form->addFieldset('googleoptimizer_fields', ['legend' => __('Google Analytics Content Experiments Code')]);
     $fieldset->addField('experiment_script', 'textarea', ['name' => 'experiment_script', 'label' => __('Experiment Code'), 'value' => $experimentCodeModel ? $experimentCodeModel->getExperimentScript() : '', 'class' => 'textarea googleoptimizer', 'required' => false, 'note' => __('Experiment code should be added to the original page only.'), 'data-form-part' => $formName]);
     $fieldset->addField('code_id', 'hidden', ['name' => 'code_id', 'value' => $experimentCodeModel ? $experimentCodeModel->getCodeId() : '', 'required' => false, 'data-form-part' => $formName]);
     $form->setFieldNameSuffix('google_experiment');
 }
Exemplo n.º 6
0
 /**
  * Form post init
  *
  * @param \Magento\Framework\Data\Form $form
  * @return $this
  */
 protected function _formPostInit($form)
 {
     $form->setAction($this->_adminhtmlData->getUrl('adminhtml/*/save', array('id' => $this->_getModel()->getId(), 'product' => $this->_getProduct()->getId(), 'category' => $this->_getCategory()->getId())));
     /** @var $requestPath \Magento\Framework\Data\Form\Element\AbstractElement */
     $requestPath = $this->getForm()->getElement('request_path');
     /** @var $targetPath \Magento\Framework\Data\Form\Element\AbstractElement */
     $targetPath = $this->getForm()->getElement('target_path');
     $model = $this->_getModel();
     $disablePaths = false;
     if (!$model->getId()) {
         $product = null;
         $category = null;
         if ($this->_getProduct()->getId()) {
             $product = $this->_getProduct();
             $category = $this->_getCategory();
         } elseif ($this->_getCategory()->getId()) {
             $category = $this->_getCategory();
         }
         if ($product || $category) {
             $sessionData = $this->_getSessionData();
             if (!isset($sessionData['request_path'])) {
                 $requestPath->setValue($this->_catalogUrl->generatePath('request', $product, $category, ''));
             }
             $targetPath->setValue($this->_catalogUrl->generatePath('target', $product, $category));
             $disablePaths = true;
         }
     } else {
         $disablePaths = in_array($model->getEntityType(), [UrlRedirect::ENTITY_TYPE_PRODUCT, UrlRedirect::ENTITY_TYPE_CATEGORY, UrlRedirect::ENTITY_TYPE_CMS_PAGE]);
     }
     if ($disablePaths) {
         $targetPath->setData('disabled', true);
     }
     return $this;
 }
Exemplo n.º 7
0
 public function testGetAttributeFieldName()
 {
     $name = 'product[image]';
     $attribute = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], [], '', false);
     $attribute->expects($this->once())->method('getAttributeCode')->willReturn('image');
     $this->formMock->expects($this->once())->method('addSuffixToName')->willReturn($name);
     $this->assertSame($name, $this->gallery->getAttributeFieldName($attribute));
 }
 /**
  * @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);
 }
 /**
  * @dataProvider dataAddFields
  */
 public function testAddFields($expected)
 {
     $this->moduleManagerMock->expects($this->once())->method('isOutputEnabled')->willReturn($expected['isOutputEnabled']);
     $this->eventObserverMock->expects($this->exactly($expected['methods_count']))->method('getForm')->willReturn($this->formMock);
     $element = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\AbstractElement', [], [], '', false);
     $this->formMock->expects($this->exactly($expected['methods_count']))->method('getElement')->with('base_fieldset')->willReturn($element);
     $element->expects($this->exactly($expected['addField_count']))->method('addField');
     $this->yesNoMock->expects($this->exactly($expected['yesno_count']))->method('toOptionArray');
     $this->observerMock->execute($this->eventObserverMock);
 }
 /**
  * @covers \Magento\Eav\Block\Adminhtml\Attribute\PropertyLocker::lock
  */
 public function testLock()
 {
     $lockedFields = ['is_searchable' => 'is_searchable', 'is_filterable' => 'is_filterable'];
     $this->attributeMock->expects($this->once())->method('getId')->willReturn(1);
     $this->attributeConfigMock->expects($this->once())->method('getLockedFields')->willReturn($lockedFields);
     $elementMock = $this->getMockBuilder('\\Magento\\Framework\\Data\\Form\\Element\\AbstractElement')->setMethods(['setDisabled', 'setReadonly'])->disableOriginalConstructor()->getMockForAbstractClass();
     $elementMock->expects($this->exactly(2))->method('setDisabled');
     $elementMock->expects($this->exactly(2))->method('setReadonly');
     $this->formMock->expects($this->exactly(2))->method('getElement')->willReturn($elementMock);
     $this->object->lock($this->formMock);
 }
 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');
 }
Exemplo n.º 12
0
 /**
  * @param \Magento\Framework\Data\Form $form
  * @return void
  */
 public function lock(\Magento\Framework\Data\Form $form)
 {
     /** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attributeObject */
     $attributeObject = $this->registry->registry('entity_attribute');
     if ($attributeObject->getId()) {
         foreach ($this->attributeConfig->getLockedFields($attributeObject) as $field) {
             if ($element = $form->getElement($field)) {
                 $element->setDisabled(1);
                 $element->setReadonly(1);
             }
         }
     }
 }
Exemplo n.º 13
0
 /**
  * Set form object
  *
  * @param \Magento\Framework\Data\Form $form
  * @return $this
  */
 public function setForm(\Magento\Framework\Data\Form $form)
 {
     $this->_form = $form;
     $this->_form->setParent($this);
     $this->_form->setBaseUrl($this->_urlBuilder->getBaseUrl());
     return $this;
 }
Exemplo n.º 14
0
 /**
  * Prepare global layout
  * Add renderers to \Magento\Framework\Data\Form
  *
  * @return $this
  */
 protected function _prepareLayout()
 {
     parent::_prepareLayout();
     \Magento\Framework\Data\Form::setElementRenderer($this->getLayout()->createBlock('Magento\\Backend\\Block\\Widget\\Form\\Renderer\\Element', $this->getNameInLayout() . '_element'));
     \Magento\Framework\Data\Form::setFieldsetRenderer($this->getLayout()->createBlock('Magento\\Backend\\Block\\Widget\\Form\\Renderer\\Fieldset', $this->getNameInLayout() . '_fieldset'));
     \Magento\Framework\Data\Form::setFieldsetElementRenderer($this->getLayout()->createBlock('Magento\\Backend\\Block\\Widget\\Form\\Renderer\\Fieldset\\Element', $this->getNameInLayout() . '_fieldset_element'));
     return $this;
 }
Exemplo n.º 15
0
 public function testAddEllement()
 {
     $this->_factoryCollectionMock->expects($this->any())->method('create')->will($this->returnValue($this->allElementsMock));
     $this->_form = new Form($this->_factoryElementMock, $this->_factoryCollectionMock, $this->_formKeyMock);
     $this->elementMock->expects($this->any())->method('getId')->will($this->returnValue('element_id'));
     $this->allElementsMock->expects($this->exactly(2))->method('add')->with($this->elementMock, false);
     $this->_form->addElement($this->elementMock);
 }
 /**
  * Retrieve attribute field name
  *
  *
  * @param Attribute $attribute
  * @return string
  */
 public function getAttributeFieldName($attribute)
 {
     $name = $attribute->getAttributeCode();
     if ($suffix = $this->getFieldNameSuffix()) {
         $name = $this->form->addSuffixToName($name, $suffix);
     }
     return $name;
 }
Exemplo n.º 17
0
 /**
  * Form post init
  *
  * @param \Magento\Framework\Data\Form $form
  * @return \Magento\UrlRewrite\Block\Cms\Page\Edit\Form
  */
 protected function _formPostInit($form)
 {
     $cmsPage = $this->_getCmsPage();
     $form->setAction($this->_adminhtmlData->getUrl('adminhtml/*/save', ['id' => $this->_getModel()->getId(), 'cms_page' => $cmsPage->getId()]));
     // Fill request path and target path elements
     /** @var $requestPath \Magento\Framework\Data\Form\Element\AbstractElement */
     $requestPath = $this->getForm()->getElement('request_path');
     /** @var $targetPath \Magento\Framework\Data\Form\Element\AbstractElement */
     $targetPath = $this->getForm()->getElement('target_path');
     $model = $this->_getModel();
     if (!$model->getId()) {
         $sessionData = $this->_getSessionData();
         if (!isset($sessionData['request_path'])) {
             $requestPath->setValue($this->cmsPageUrlPathGenerator->getUrlPath($cmsPage));
         }
         $targetPath->setValue($this->cmsPageUrlPathGenerator->getCanonicalUrlPath($cmsPage));
     }
     $targetPath->setData('disabled', true);
     return $this;
 }
Exemplo n.º 18
0
 /**
  * @param array $values
  * @return $this
  */
 public function addValues($values)
 {
     if (!is_array($values)) {
         return $this;
     }
     $values = array_merge($values, $this->getAdditionalData($values));
     if (isset($values['frontend_input']) && 'select' == $values['frontend_input'] && isset($values[Swatch::SWATCH_INPUT_TYPE_KEY])) {
         $values['frontend_input'] = 'swatch_' . $values[Swatch::SWATCH_INPUT_TYPE_KEY];
     }
     return parent::addValues($values);
 }
Exemplo n.º 19
0
 /**
  * Add Fieldset with Store labels
  *
  * @param \Magento\Sales\Model\Order\Status $model
  * @param \Magento\Framework\Data\Form $form
  * @return void
  */
 protected function _addStoresFieldset($model, $form)
 {
     $labels = $model ? $model->getStoreLabels() : [];
     $fieldset = $form->addFieldset('store_labels_fieldset', ['legend' => __('Store View Specific Labels'), 'class' => 'store-scope']);
     $renderer = $this->getLayout()->createBlock('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset');
     $fieldset->setRenderer($renderer);
     foreach ($this->_storeManager->getWebsites() as $website) {
         $fieldset->addField("w_{$website->getId()}_label", 'note', ['label' => $website->getName(), 'fieldset_html_class' => 'website']);
         foreach ($website->getGroups() as $group) {
             $stores = $group->getStores();
             if (count($stores) == 0) {
                 continue;
             }
             $fieldset->addField("sg_{$group->getId()}_label", 'note', ['label' => $group->getName(), 'fieldset_html_class' => 'store-group']);
             foreach ($stores as $store) {
                 $fieldset->addField("store_label_{$store->getId()}", 'text', ['name' => 'store_labels[' . $store->getId() . ']', 'required' => false, 'label' => $store->getName(), 'value' => isset($labels[$store->getId()]) ? $labels[$store->getId()] : '', 'fieldset_html_class' => 'store']);
             }
         }
     }
 }
Exemplo n.º 20
0
 public function testElementOperations()
 {
     $buttonElement = $this->getMockBuilder('Magento\\Framework\\Data\\Form\\Element\\Button')->disableOriginalConstructor()->getMock();
     $buttonElement->expects($this->any())->method('getId')->will($this->returnValue('1'));
     $buttonElement->expects($this->any())->method('getName')->will($this->returnValue('Hero'));
     $this->_form->addElement($buttonElement);
     $this->_form->addElementToCollection($buttonElement);
     $this->_form->addValues(['1', '2', '3']);
     $this->_form->setValues(['4', '5', '6']);
     $this->_form->addFieldNameSuffix('abc123');
     $this->_form->removeField($buttonElement->getId());
     $this->assertSame($this->_form->checkElementId($buttonElement->getId()), true);
 }
Exemplo n.º 21
0
 public function testToHtmlCoreRegistryRatingData()
 {
     $this->registry->expects($this->any())->method('registry')->will($this->returnValue($this->rating));
     $this->form->expects($this->at(7))->method('getElement')->will($this->returnValue($this->element));
     $this->form->expects($this->at(13))->method('getElement')->will($this->returnValue($this->element));
     $this->form->expects($this->at(16))->method('getElement')->will($this->returnValue($this->element));
     $this->form->expects($this->at(17))->method('getElement')->will($this->returnValue($this->element));
     $this->form->expects($this->any())->method('getElement')->will($this->returnValue(false));
     $this->session->expects($this->any())->method('getRatingData')->will($this->returnValue(false));
     $ratingCodes = ['rating_codes' => ['0' => 'rating_code']];
     $this->rating->expects($this->any())->method('getRatingCodes')->will($this->returnValue($ratingCodes));
     $this->block->toHtml();
 }
Exemplo n.º 22
0
 /**
  * Set form object
  *
  * @param \Magento\Framework\Data\Form $form
  * @return $this
  */
 public function setForm(\Magento\Framework\Data\Form $form)
 {
     $this->_form = $form;
     $this->_form->setParent($this);
     $this->_form->setBaseUrl($this->_urlBuilder->getBaseUrl());
     $customAttributes = $this->getData('custom_attributes');
     if (is_array($customAttributes)) {
         foreach ($customAttributes as $key => $value) {
             $this->_form->addCustomAttribute($key, $value);
         }
     }
     return $this;
 }
Exemplo n.º 23
0
 /**
  * Prepare website specific fieldset
  *
  * @param \Magento\Framework\Data\Form $form
  * @return void
  */
 protected function _prepareStoreFieldset(\Magento\Framework\Data\Form $form)
 {
     $websiteModel = $this->_coreRegistry->registry('store_data');
     $postData = $this->_coreRegistry->registry('store_post_data');
     if ($postData) {
         $websiteModel->setData($postData['website']);
     }
     $fieldset = $form->addFieldset('website_fieldset', array('legend' => __('Web Site Information')));
     /* @var $fieldset \Magento\Framework\Data\Form */
     $fieldset->addField('website_name', 'text', array('name' => 'website[name]', 'label' => __('Name'), 'value' => $websiteModel->getName(), 'required' => true, 'disabled' => $websiteModel->isReadOnly()));
     $fieldset->addField('website_code', 'text', array('name' => 'website[code]', 'label' => __('Code'), 'value' => $websiteModel->getCode(), 'required' => true, 'disabled' => $websiteModel->isReadOnly()));
     $fieldset->addField('website_sort_order', 'text', array('name' => 'website[sort_order]', 'label' => __('Sort Order'), 'value' => $websiteModel->getSortOrder(), 'required' => false, 'disabled' => $websiteModel->isReadOnly()));
     if ($this->_coreRegistry->registry('store_action') == 'edit') {
         $groups = $this->_groupFactory->create()->getCollection()->addWebsiteFilter($websiteModel->getId())->setWithoutStoreViewFilter()->toOptionArray();
         $fieldset->addField('website_default_group_id', 'select', array('name' => 'website[default_group_id]', 'label' => __('Default Store'), 'value' => $websiteModel->getDefaultGroupId(), 'values' => $groups, 'required' => false, 'disabled' => $websiteModel->isReadOnly()));
     }
     if (!$websiteModel->getIsDefault() && $websiteModel->getStoresCount()) {
         $fieldset->addField('is_default', 'checkbox', array('name' => 'website[is_default]', 'label' => __('Set as Default'), 'value' => 1, 'disabled' => $websiteModel->isReadOnly()));
     } else {
         $fieldset->addField('is_default', 'hidden', array('name' => 'website[is_default]', 'value' => $websiteModel->getIsDefault()));
     }
     $fieldset->addField('website_website_id', 'hidden', array('name' => 'website[website_id]', 'value' => $websiteModel->getId()));
 }
Exemplo n.º 24
0
 /**
  * Form post init
  *
  * @param \Magento\Framework\Data\Form $form
  * @return \Magento\Backend\Block\Urlrewrite\Catalog\Edit\Form
  */
 protected function _formPostInit($form)
 {
     // Set form action
     $form->setAction($this->_adminhtmlData->getUrl('adminhtml/*/save', array('id' => $this->_getModel()->getId(), 'product' => $this->_getProduct()->getId(), 'category' => $this->_getCategory()->getId())));
     // Fill id path, request path and target path elements
     /** @var $idPath \Magento\Framework\Data\Form\Element\AbstractElement */
     $idPath = $this->getForm()->getElement('id_path');
     /** @var $requestPath \Magento\Framework\Data\Form\Element\AbstractElement */
     $requestPath = $this->getForm()->getElement('request_path');
     /** @var $targetPath \Magento\Framework\Data\Form\Element\AbstractElement */
     $targetPath = $this->getForm()->getElement('target_path');
     $model = $this->_getModel();
     $disablePaths = false;
     if (!$model->getId()) {
         $product = null;
         $category = null;
         if ($this->_getProduct()->getId()) {
             $product = $this->_getProduct();
             $category = $this->_getCategory();
         } elseif ($this->_getCategory()->getId()) {
             $category = $this->_getCategory();
         }
         if ($product || $category) {
             $idPath->setValue($this->_catalogUrl->generatePath('id', $product, $category));
             $sessionData = $this->_getSessionData();
             if (!isset($sessionData['request_path'])) {
                 $requestPath->setValue($this->_catalogUrl->generatePath('request', $product, $category, ''));
             }
             $targetPath->setValue($this->_catalogUrl->generatePath('target', $product, $category));
             $disablePaths = true;
         }
     } else {
         $disablePaths = $model->getProductId() || $model->getCategoryId();
     }
     // Disable id_path and target_path elements
     if ($disablePaths) {
         $idPath->setData('disabled', true);
         $targetPath->setData('disabled', true);
     }
     return $this;
 }
Exemplo n.º 25
0
 /**
  * @param Factory $factoryElement
  * @param CollectionFactory $factoryCollection
  * @param Escaper $escaper
  * @param array $data
  */
 public function __construct(Factory $factoryElement, CollectionFactory $factoryCollection, Escaper $escaper, $data = array())
 {
     $this->_escaper = $escaper;
     parent::__construct($factoryElement, $factoryCollection, $data);
     $this->_renderer = \Magento\Framework\Data\Form::getElementRenderer();
 }
Exemplo n.º 26
0
 /**
  * Handle Read-Only customer
  *
  * @param \Magento\Framework\Data\Form $form
  * @param int $customerId
  * @param \Magento\Customer\Service\V1\Data\Eav\AttributeMetadata[] $attributes
  * @return void
  */
 protected function _handleReadOnlyCustomer($form, $customerId, $attributes)
 {
     if ($customerId && !$this->_customerAccountService->canModify($customerId)) {
         foreach ($attributes as $attribute) {
             $element = $form->getElement($attribute->getAttributeCode());
             if ($element) {
                 $element->setReadonly(true, true);
             }
         }
     }
 }
Exemplo n.º 27
0
 /**
  * Reset application global state
  */
 protected function _resetApp()
 {
     /** @var $objectManager \Magento\TestFramework\ObjectManager */
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $objectManager->clearCache();
     \Magento\Framework\Data\Form::setElementRenderer(null);
     \Magento\Framework\Data\Form::setFieldsetRenderer(null);
     \Magento\Framework\Data\Form::setFieldsetElementRenderer(null);
     $this->_appArea = null;
 }
Exemplo n.º 28
0
 /**
  * Form post init
  *
  * @param \Magento\Framework\Data\Form $form
  * @return $this
  */
 protected function _formPostInit($form)
 {
     $form->setAction($this->_adminhtmlData->getUrl('adminhtml/*/save', ['id' => $this->_getModel()->getId()]));
     return $this;
 }
Exemplo n.º 29
0
 /**
  * Add fieldset with integration details. This fieldset is available for existing integrations only.
  *
  * @param \Magento\Framework\Data\Form $form
  * @param array $integrationData
  * @return void
  */
 protected function _addDetailsFieldset($form, $integrationData)
 {
     if (isset($integrationData[self::DATA_ID])) {
         $fieldset = $form->addFieldset('details_fieldset', ['legend' => __('Integration Details')]);
         /** @var \Magento\Integration\Block\Adminhtml\Integration\Tokens $tokensBlock */
         $tokensBlock = $this->getChildBlock('integration_tokens');
         foreach ($tokensBlock->getFormFields() as $field) {
             $fieldset->addField($field['name'], $field['type'], $field['metadata']);
         }
     }
 }
Exemplo n.º 30
-3
 /**
  * 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);
 }