/** * Adding product form elements for editing attribute * * @return $this */ protected function _prepareForm() { $attributeObject = $this->getAttributeObject(); $form = $this->_formFactory->create(array('data' => array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'))); $fieldset = $form->addFieldset('advanced_fieldset', array('legend' => __('Advanced Attribute Properties'), 'collapsable' => true)); $yesno = $this->_yesNo->toOptionArray(); $validateClass = sprintf('validate-code validate-length maximum-length-%d', \Magento\Eav\Model\Entity\Attribute::ATTRIBUTE_CODE_MAX_LENGTH); $fieldset->addField('attribute_code', 'text', array('name' => 'attribute_code', 'label' => __('Attribute Code'), 'title' => __('Attribute Code'), 'note' => __('For internal use. Must be unique with no spaces. Maximum length of attribute code must be less than %1 symbols', \Magento\Eav\Model\Entity\Attribute::ATTRIBUTE_CODE_MAX_LENGTH), 'class' => $validateClass)); $fieldset->addField('default_value_text', 'text', array('name' => 'default_value_text', 'label' => __('Default Value'), 'title' => __('Default Value'), 'value' => $attributeObject->getDefaultValue())); $fieldset->addField('default_value_yesno', 'select', array('name' => 'default_value_yesno', 'label' => __('Default Value'), 'title' => __('Default Value'), 'values' => $yesno, 'value' => $attributeObject->getDefaultValue())); $dateFormat = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT); $fieldset->addField('default_value_date', 'date', array('name' => 'default_value_date', 'label' => __('Default Value'), 'title' => __('Default Value'), 'image' => $this->getViewFileUrl('images/grid-cal.gif'), 'value' => $attributeObject->getDefaultValue(), 'date_format' => $dateFormat)); $fieldset->addField('default_value_textarea', 'textarea', array('name' => 'default_value_textarea', 'label' => __('Default Value'), 'title' => __('Default Value'), 'value' => $attributeObject->getDefaultValue())); $fieldset->addField('is_unique', 'select', array('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', array('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); if (!$attributeObject->getIsUserDefined()) { $form->getElement('is_unique')->setDisabled(1); } } $scopes = array(\Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_STORE => __('Store View'), \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_WEBSITE => __('Website'), \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_GLOBAL => __('Global')); if ($attributeObject->getAttributeCode() == 'status' || $attributeObject->getAttributeCode() == 'tax_class_id') { unset($scopes[\Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_STORE]); } $fieldset->addField('is_global', 'select', array('name' => 'is_global', 'label' => __('Scope'), 'title' => __('Scope'), 'note' => __('Declare attribute value saving scope'), 'values' => $scopes), 'attribute_code'); $this->_eventManager->dispatch('product_attribute_form_build', array('form' => $form)); $this->setForm($form); return $this; }
/** * {@inheritdoc} * @return $this */ protected function _prepareForm() { $attributeObject = $this->_coreRegistry->registry('entity_attribute'); /** @var \Magento\Framework\Data\Form $form */ $form = $this->_formFactory->create(array('data' => array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'))); $yesnoSource = $this->_yesNo->toOptionArray(); $fieldset = $form->addFieldset('front_fieldset', array('legend' => __('Frontend Properties'), 'collapsable' => $this->getRequest()->has('popup'))); $fieldset->addField('is_searchable', 'select', array('name' => 'is_searchable', 'label' => __('Use in Quick Search'), 'title' => __('Use in Quick Search'), 'values' => $yesnoSource)); $fieldset->addField('is_visible_in_advanced_search', 'select', array('name' => 'is_visible_in_advanced_search', 'label' => __('Use in Advanced Search'), 'title' => __('Use in Advanced Search'), 'values' => $yesnoSource)); $fieldset->addField('is_comparable', 'select', array('name' => 'is_comparable', 'label' => __('Comparable on Frontend'), 'title' => __('Comparable on Frontend'), 'values' => $yesnoSource)); $this->_eventManager->dispatch('product_attribute_form_build_front_tab', array('form' => $form)); $fieldset->addField('is_used_for_promo_rules', 'select', array('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', array('name' => 'is_wysiwyg_enabled', 'label' => __('Enable WYSIWYG'), 'title' => __('Enable WYSIWYG'), 'values' => $yesnoSource)); $fieldset->addField('is_html_allowed_on_front', 'select', array('name' => 'is_html_allowed_on_front', 'label' => __('Allow HTML Tags on Frontend'), 'title' => __('Allow HTML Tags on Frontend'), 'values' => $yesnoSource)); if (!$attributeObject->getId() || $attributeObject->getIsWysiwygEnabled()) { $attributeObject->setIsHtmlAllowedOnFront(1); } $fieldset->addField('is_visible_on_front', 'select', array('name' => 'is_visible_on_front', 'label' => __('Visible on Catalog Pages on Frontend'), 'title' => __('Visible on Catalog Pages on Frontend'), 'values' => $yesnoSource)); $fieldset->addField('used_in_product_listing', 'select', array('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', array('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', array('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')); $form->setValues($attributeObject->getData()); $this->setForm($form); return parent::_prepareForm(); }
/** * @param \Magento\Framework\Event $event * @return void */ public function observe($event) { /** @var \Magento\Framework\Data\Form\AbstractForm $form */ $form = $event->getForm(); /** @var $fieldset */ $fieldset = $form->getElement('advanced_fieldset'); $fieldset->addField('is_configurable', 'select', array('name' => 'is_configurable', 'label' => __('Use To Create Configurable Product'), 'values' => $this->optionList->toOptionArray())); }
/** * @param \Magento\Framework\Event $event * @return void */ public function observe($event) { if (!$this->moduleManager->isOutputEnabled('Magento_LayeredNavigation')) { return; } /** @var \Magento\Framework\Data\Form\AbstractForm $form */ $form = $event->getForm(); $fieldset = $form->getElement('front_fieldset'); $fieldset->addField('is_filterable', 'select', array('name' => 'is_filterable', 'label' => __("Use In Layered Navigation"), 'title' => __('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'note' => __('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'values' => array(array('value' => '0', 'label' => __('No')), array('value' => '1', 'label' => __('Filterable (with results)')), array('value' => '2', 'label' => __('Filterable (no results)'))))); $fieldset->addField('is_filterable_in_search', 'select', array('name' => 'is_filterable_in_search', 'label' => __("Use In Search Results Layered Navigation"), 'title' => __('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'note' => __('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'values' => $this->optionList->toOptionArray())); $fieldset->addField('position', 'text', array('name' => 'position', 'label' => __('Position'), 'title' => __('Position in Layered Navigation'), 'note' => __('Position of attribute in layered navigation block'), 'class' => 'validate-digits')); }
/** * Prepare form before rendering HTML * * @return $this */ protected function _prepareForm() { $model = $this->_coreRegistry->registry('current_promo_quote_rule'); /** @var \Magento\Framework\Data\Form $form */ $form = $this->_formFactory->create(); $form->setHtmlIdPrefix('rule_'); $fieldset = $form->addFieldset('action_fieldset', array('legend' => __('Update prices using the following information'))); $fieldset->addField('simple_action', 'select', array('label' => __('Apply'), 'name' => 'simple_action', 'options' => array(\Magento\SalesRule\Model\Rule::BY_PERCENT_ACTION => __('Percent of product price discount'), \Magento\SalesRule\Model\Rule::BY_FIXED_ACTION => __('Fixed amount discount'), \Magento\SalesRule\Model\Rule::CART_FIXED_ACTION => __('Fixed amount discount for whole cart'), \Magento\SalesRule\Model\Rule::BUY_X_GET_Y_ACTION => __('Buy X get Y free (discount amount is Y)')))); $fieldset->addField('discount_amount', 'text', array('name' => 'discount_amount', 'required' => true, 'class' => 'validate-not-negative-number', 'label' => __('Discount Amount'))); $model->setDiscountAmount($model->getDiscountAmount() * 1); $fieldset->addField('discount_qty', 'text', array('name' => 'discount_qty', 'label' => __('Maximum Qty Discount is Applied To'))); $model->setDiscountQty($model->getDiscountQty() * 1); $fieldset->addField('discount_step', 'text', array('name' => 'discount_step', 'label' => __('Discount Qty Step (Buy X)'))); $fieldset->addField('apply_to_shipping', 'select', array('label' => __('Apply to Shipping Amount'), 'title' => __('Apply to Shipping Amount'), 'name' => 'apply_to_shipping', 'values' => $this->_sourceYesno->toOptionArray())); $fieldset->addField('stop_rules_processing', 'select', array('label' => __('Stop Further Rules Processing'), 'title' => __('Stop Further Rules Processing'), 'name' => 'stop_rules_processing', 'options' => array('1' => __('Yes'), '0' => __('No')))); $renderer = $this->_rendererFieldset->setTemplate('Magento_CatalogRule::promo/fieldset.phtml')->setNewChildUrl($this->getUrl('sales_rule/promo_quote/newActionHtml/form/rule_actions_fieldset')); $fieldset = $form->addFieldset('actions_fieldset', array('legend' => __('Apply the rule only to cart items matching the following conditions ' . '(leave blank for all items).')))->setRenderer($renderer); $fieldset->addField('actions', 'text', array('name' => 'actions', 'label' => __('Apply To'), 'title' => __('Apply To'), 'required' => true))->setRule($model)->setRenderer($this->_ruleActions); $this->_eventManager->dispatch('adminhtml_block_salesrule_actions_prepareform', array('form' => $form)); $form->setValues($model->getData()); if ($model->isReadonly()) { foreach ($fieldset->getElements() as $element) { $element->setReadonly(true, true); } } $this->setForm($form); return parent::_prepareForm(); }
/** * @return mixed */ public function getRequireSelectHtml() { $select = $this->getLayout()->createBlock('Magento\\Framework\\View\\Element\\Html\\Select')->setData(array('id' => $this->getFieldId() . '_{{index}}_required', 'class' => 'select'))->setName($this->getFieldName() . '[{{index}}][required]')->setOptions($this->_yesno->toOptionArray()); return $select->getHtml(); }
/** * @return mixed */ public function getRequireSelectHtml() { $select = $this->getLayout()->createBlock('Magento\\Framework\\View\\Element\\Html\\Select')->setData(array('id' => $this->getFieldId() . '_${id}_is_require', 'class' => 'select'))->setName($this->getFieldName() . '[${id}][is_require]')->setOptions($this->_configYesNo->toOptionArray()); return $select->getHtml(); }
/** * Retrieve Purchased Separately HTML select * * @return string */ public function getPurchasedSeparatelySelect() { $select = $this->getLayout()->createBlock('Magento\\Framework\\View\\Element\\Html\\Select')->setName('product[links_purchased_separately]')->setId('downloadable_link_purchase_type')->setOptions($this->_sourceModel->toOptionArray())->setValue($this->getProduct()->getLinksPurchasedSeparately()); return $select->getHtml(); }
/** * Retrieve qty type select html * * @return string */ public function getQtyTypeSelectHtml() { $select = $this->getLayout()->createBlock('Magento\\Framework\\View\\Element\\Html\\Select')->setData(array('id' => $this->getFieldId() . '_{{index}}_can_change_qty', 'class' => 'select'))->setName($this->getFieldName() . '[{{parentIndex}}][{{index}}][selection_can_change_qty]')->setOptions($this->_yesno->toOptionArray()); return $select->getHtml(); }