Esempio n. 1
0
 /**
  * {@inheritdoc}
  * @return $this
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _prepareForm()
 {
     /** @var Attribute $attributeObject */
     $attributeObject = $this->_coreRegistry->registry('entity_attribute');
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create(['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]);
     $yesnoSource = $this->_yesNo->toOptionArray();
     $fieldset = $form->addFieldset('front_fieldset', ['legend' => __('Storefront Properties'), 'collapsable' => $this->getRequest()->has('popup')]);
     $fieldset->addField('is_searchable', 'select', ['name' => 'is_searchable', 'label' => __('Use in Search'), 'title' => __('Use in Search'), 'values' => $yesnoSource]);
     $fieldset->addField('is_visible_in_advanced_search', 'select', ['name' => 'is_visible_in_advanced_search', 'label' => __('Visible in Advanced Search'), 'title' => __('Visible in Advanced Search'), 'values' => $yesnoSource]);
     $fieldset->addField('is_comparable', 'select', ['name' => 'is_comparable', 'label' => __('Comparable on Storefront'), 'title' => __('Comparable on Storefront'), 'values' => $yesnoSource]);
     $this->_eventManager->dispatch('product_attribute_form_build_front_tab', ['form' => $form]);
     $fieldset->addField('is_used_for_promo_rules', 'select', ['name' => 'is_used_for_promo_rules', 'label' => __('Use for Promo Rule Conditions'), 'title' => __('Use for Promo Rule Conditions'), 'values' => $yesnoSource]);
     $fieldset->addField('is_wysiwyg_enabled', 'select', ['name' => 'is_wysiwyg_enabled', 'label' => __('Enable WYSIWYG'), 'title' => __('Enable WYSIWYG'), 'values' => $yesnoSource]);
     $fieldset->addField('is_html_allowed_on_front', 'select', ['name' => 'is_html_allowed_on_front', 'label' => __('Allow HTML Tags on Storefront'), 'title' => __('Allow HTML Tags on Storefront'), 'values' => $yesnoSource]);
     if (!$attributeObject->getId() || $attributeObject->getIsWysiwygEnabled()) {
         $attributeObject->setIsHtmlAllowedOnFront(1);
     }
     $fieldset->addField('is_visible_on_front', 'select', ['name' => 'is_visible_on_front', 'label' => __('Visible on Catalog Pages on Storefront'), 'title' => __('Visible on Catalog Pages on Storefront'), 'values' => $yesnoSource]);
     $fieldset->addField('used_in_product_listing', 'select', ['name' => 'used_in_product_listing', 'label' => __('Used in Product Listing'), 'title' => __('Used in Product Listing'), 'note' => __('Depends on design theme.'), 'values' => $yesnoSource]);
     $fieldset->addField('used_for_sort_by', 'select', ['name' => 'used_for_sort_by', 'label' => __('Used for Sorting in Product Listing'), 'title' => __('Used for Sorting in Product Listing'), 'note' => __('Depends on design theme.'), 'values' => $yesnoSource]);
     $this->_eventManager->dispatch('adminhtml_catalog_product_attribute_edit_frontend_prepare_form', ['form' => $form, 'attribute' => $attributeObject]);
     // define field dependencies
     $this->setChild('form_after', $this->getLayout()->createBlock('Magento\\Backend\\Block\\Widget\\Form\\Element\\Dependence')->addFieldMap("is_wysiwyg_enabled", 'wysiwyg_enabled')->addFieldMap("is_html_allowed_on_front", 'html_allowed_on_front')->addFieldMap("frontend_input", 'frontend_input_type')->addFieldDependence('wysiwyg_enabled', 'frontend_input_type', 'textarea')->addFieldDependence('html_allowed_on_front', 'wysiwyg_enabled', '0')->addFieldMap("is_searchable", 'searchable')->addFieldMap("is_visible_in_advanced_search", 'advanced_search')->addFieldDependence('advanced_search', 'searchable', '1'));
     $this->setForm($form);
     $form->setValues($attributeObject->getData());
     $this->propertyLocker->lock($form);
     return parent::_prepareForm();
 }
Esempio n. 2
0
 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(2))->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->propertyLocker->expects($this->once())->method('lock')->with($form);
     $this->block->setData(['action' => 'save']);
     $this->block->toHtml();
 }
 /**
  * @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);
 }
Esempio n. 4
0
 /**
  * Preparing default form elements for editing attribute
  *
  * @return $this
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _prepareForm()
 {
     $attributeObject = $this->getAttributeObject();
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create(['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]);
     $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Attribute Properties')]);
     if ($attributeObject->getAttributeId()) {
         $fieldset->addField('attribute_id', 'hidden', ['name' => 'attribute_id']);
     }
     $this->_addElementTypes($fieldset);
     $yesno = $this->_yesnoFactory->create()->toOptionArray();
     $labels = $attributeObject->getFrontendLabel();
     $fieldset->addField('attribute_label', 'text', ['name' => 'frontend_label[0]', 'label' => __('Default Label'), 'title' => __('Default label'), 'required' => true, 'value' => is_array($labels) ? $labels[0] : $labels]);
     $validateClass = sprintf('validate-code validate-length maximum-length-%d', \Magento\Eav\Model\Entity\Attribute::ATTRIBUTE_CODE_MAX_LENGTH);
     $fieldset->addField('attribute_code', 'text', ['name' => 'attribute_code', 'label' => __('Attribute Code'), 'title' => __('Attribute Code'), 'note' => __('This is used internally. Make sure you don\'t use spaces or more than %1 symbols.', \Magento\Eav\Model\Entity\Attribute::ATTRIBUTE_CODE_MAX_LENGTH), 'class' => $validateClass, 'required' => true]);
     $fieldset->addField('frontend_input', 'select', ['name' => 'frontend_input', 'label' => __('Catalog Input Type for Store Owner'), 'title' => __('Catalog Input Type for Store Owner'), 'value' => 'text', 'values' => $this->_inputTypeFactory->create()->toOptionArray()]);
     $fieldset->addField('is_required', 'select', ['name' => 'is_required', 'label' => __('Values Required'), 'title' => __('Values Required'), 'values' => $yesno]);
     $fieldset->addField('default_value_text', 'text', ['name' => 'default_value_text', 'label' => __('Default Value'), 'title' => __('Default Value'), 'value' => $attributeObject->getDefaultValue()]);
     $fieldset->addField('default_value_yesno', 'select', ['name' => 'default_value_yesno', 'label' => __('Default Value'), 'title' => __('Default Value'), 'values' => $yesno, 'value' => $attributeObject->getDefaultValue()]);
     $dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
     $fieldset->addField('default_value_date', 'date', ['name' => 'default_value_date', 'label' => __('Default Value'), 'title' => __('Default Value'), 'value' => $attributeObject->getDefaultValue(), 'date_format' => $dateFormat]);
     $fieldset->addField('default_value_textarea', 'textarea', ['name' => 'default_value_textarea', 'label' => __('Default Value'), 'title' => __('Default Value'), 'value' => $attributeObject->getDefaultValue()]);
     $fieldset->addField('is_unique', 'select', ['name' => 'is_unique', 'label' => __('Unique Value'), 'title' => __('Unique Value (not shared with other products)'), 'note' => __('Not shared with other products.'), 'values' => $yesno]);
     $fieldset->addField('frontend_class', 'select', ['name' => 'frontend_class', 'label' => __('Input Validation for Store Owner'), 'title' => __('Input Validation for Store Owner'), 'values' => $this->_eavData->getFrontendClasses($attributeObject->getEntityType()->getEntityTypeCode())]);
     if ($attributeObject->getId()) {
         $form->getElement('attribute_code')->setDisabled(1);
         $form->getElement('frontend_input')->setDisabled(1);
         if (!$attributeObject->getIsUserDefined()) {
             $form->getElement('is_unique')->setDisabled(1);
         }
     }
     $this->propertyLocker->lock($form);
     $this->setForm($form);
     return parent::_prepareForm();
 }