/** * Adds 'used_in_recommender' form field * @param \Magento\Framework\Event\Observer $observer * @return void */ public function addUsedInRecommender(\Magento\Framework\Event\Observer $observer) { /** @var \Magento\Framework\Data\Form $form */ $form = $observer->getEvent()->getForm(); $fieldset = $form->getElement('advanced_fieldset'); $fieldset->addField('used_in_recommender', 'select', ['name' => 'used_in_recommender', 'label' => __('Used in Recommender'), 'title' => __('Used in Recommender (Exported to the recommender system)'), 'note' => __('Exported to the recommender system'), 'values' => $this->_yesNo->toOptionArray()]); }
/** * {@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(); }
/** * Adding product form elements for editing attribute * * @return $this * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function _prepareForm() { $attributeObject = $this->getAttributeObject(); $form = $this->_formFactory->create(['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]); $fieldset = $form->addFieldset('advanced_fieldset', ['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', ['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]); $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); if (!$attributeObject->getIsUserDefined()) { $form->getElement('is_unique')->setDisabled(1); } } $scopes = [\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', ['name' => 'is_global', 'label' => __('Scope'), 'title' => __('Scope'), 'note' => __('Declare attribute value saving scope'), 'values' => $scopes], 'attribute_code'); $this->_eventManager->dispatch('product_attribute_form_build', ['form' => $form]); if ($attributeObject->getId() && !$attributeObject->getIsUserDefined()) { $form->getElement('is_global')->setDisabled(1); } $this->setForm($form); return $this; }
/** * Prepare form * * @return $this */ protected function _prepareForm() { /** @var \Mageplaza\Blog\Model\Topic $topic */ $topic = $this->_coreRegistry->registry('mageplaza_blog_topic'); $form = $this->_formFactory->create(); $form->setHtmlIdPrefix('topic_'); $form->setFieldNameSuffix('topic'); $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Topic Information'), 'class' => 'fieldset-wide']); if ($topic->getId()) { $fieldset->addField('topic_id', 'hidden', ['name' => 'topic_id']); } $fieldset->addField('name', 'text', ['name' => 'name', 'label' => __('Name'), 'title' => __('Name'), 'required' => true]); $fieldset->addField('description', 'editor', ['name' => 'description', 'label' => __('Description'), 'title' => __('Description'), 'config' => $this->wysiwygConfig->getConfig()]); $fieldset->addField('enabled', 'select', ['name' => 'enabled', 'label' => __('Enabled'), 'title' => __('Enabled'), 'values' => $this->booleanOptions->toOptionArray()]); $fieldset->addField('url_key', 'text', ['name' => 'url_key', 'label' => __('URL Key'), 'title' => __('URL Key')]); $fieldset->addField('meta_title', 'text', ['name' => 'meta_title', 'label' => __('Meta Title'), 'title' => __('Meta Title')]); $fieldset->addField('meta_description', 'textarea', ['name' => 'meta_description', 'label' => __('Meta Description'), 'title' => __('Meta Description')]); $fieldset->addField('meta_keywords', 'textarea', ['name' => 'meta_keywords', 'label' => __('Meta Keywords'), 'title' => __('Meta Keywords')]); $fieldset->addField('meta_robots', 'select', ['name' => 'meta_robots', 'label' => __('Meta Robots'), 'title' => __('Meta Robots'), 'values' => array_merge(['' => ''], $this->metaRobotsOptions->toOptionArray())]); $topicData = $this->_session->getData('mageplaza_blog_topic_data', true); if ($topicData) { $topic->addData($topicData); } else { if (!$topic->getId()) { $topic->addData($topic->getDefaultValues()); } } $form->addValues($topic->getData()); $this->setForm($form); return parent::_prepareForm(); }
/** * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute(\Magento\Framework\Event\Observer $observer) { if (!$this->moduleManager->isOutputEnabled('Magento_LayeredNavigation')) { return; } /** @var \Magento\Framework\Data\Form\AbstractForm $form */ $form = $observer->getForm(); $fieldset = $form->getElement('front_fieldset'); $fieldset->addField('is_filterable', 'select', ['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' => [['value' => '0', 'label' => __('No')], ['value' => '1', 'label' => __('Filterable (with results)')], ['value' => '2', 'label' => __('Filterable (no results)')]]]); $fieldset->addField('is_filterable_in_search', 'select', ['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', ['name' => 'position', 'label' => __('Position'), 'title' => __('Position in Layered Navigation'), 'note' => __('Position of attribute in layered navigation block.'), 'class' => 'validate-digits']); }
/** * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute(EventObserver $observer) { if (!$this->moduleManager->isOutputEnabled('Magento_Swatches')) { return; } /** @var \Magento\Framework\Data\Form $form */ $form = $observer->getForm(); $fieldset = $form->getElement('base_fieldset'); $yesnoSource = $this->yesNo->toOptionArray(); $fieldset->addField('update_product_preview_image', 'select', ['name' => 'update_product_preview_image', 'label' => __('Update Product Preview Image'), 'title' => __('Update Product Preview Image'), 'note' => __('Filtering by this attribute will update the product image on catalog page'), 'values' => $yesnoSource], 'is_filterable'); $fieldset->addField('use_product_image_for_swatch', 'select', ['name' => 'use_product_image_for_swatch', 'label' => __('Use Product Image for Swatch if Possible'), 'title' => __('Use Product Image for Swatch if Possible'), 'note' => __('Allows use fallback logic for replacing swatch image with product swatch or base image'), 'values' => $yesnoSource], 'is_filterable'); }
/** * Prepare form before rendering HTML * * @return $this * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ 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', ['legend' => __('Pricing Structure Rules')]); $fieldset->addField('simple_action', 'select', ['label' => __('Apply'), 'name' => 'simple_action', 'options' => [\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', ['name' => 'discount_amount', 'required' => true, 'class' => 'validate-not-negative-number', 'label' => __('Discount Amount')]); $model->setDiscountAmount($model->getDiscountAmount() * 1); $fieldset->addField('discount_qty', 'text', ['name' => 'discount_qty', 'label' => __('Maximum Qty Discount is Applied To')]); $model->setDiscountQty($model->getDiscountQty() * 1); $fieldset->addField('discount_step', 'text', ['name' => 'discount_step', 'label' => __('Discount Qty Step (Buy X)')]); $fieldset->addField('apply_to_shipping', 'select', ['label' => __('Apply to Shipping Amount'), 'title' => __('Apply to Shipping Amount'), 'name' => 'apply_to_shipping', 'values' => $this->_sourceYesno->toOptionArray()]); $fieldset->addField('stop_rules_processing', 'select', ['label' => __('Discard subsequent rules'), 'title' => __('Discard subsequent rules'), 'name' => 'stop_rules_processing', 'options' => ['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', ['legend' => __('Apply the rule only to cart items matching the following conditions ' . '(leave blank for all items).')])->setRenderer($renderer); $fieldset->addField('actions', 'text', ['name' => 'actions', 'label' => __('Apply To'), 'title' => __('Apply To'), 'required' => true])->setRule($model)->setRenderer($this->_ruleActions); $this->_eventManager->dispatch('adminhtml_block_salesrule_actions_prepareform', ['form' => $form]); $form->setValues($model->getData()); if ($model->isReadonly()) { foreach ($fieldset->getElements() as $element) { $element->setReadonly(true, true); } } $this->setForm($form); return parent::_prepareForm(); }
/** * @SuppressWarnings(PHPMD.CamelCaseMethodName) * @SuppressWarnings(PHPMD.ElseExpression) * * {@inheritDoc} */ protected function _prepareValueOptions() { $selectReady = $this->getData('value_select_options'); $hashedReady = $this->getData('value_option'); if (in_array($this->getAttribute(), ['stock.is_in_stock', 'has_image', 'price.is_discount'])) { $selectOptions = $this->booleanSource->toOptionArray(); $this->_setSelectOptions($selectOptions, $selectReady, $hashedReady); } else { parent::_prepareValueOptions(); } }
/** * Init base fields : * - thesaurus name * - store id * * @param \Magento\Framework\Data\Form\Element\Fieldset $fieldset The fieldset * @param \Smile\ElasticsuiteThesaurus\Model\Thesaurus|null $model Current Thesaurus * * @throws \Magento\Framework\Exception\LocalizedException * @SuppressWarnings(PHPMD.ElseExpression) * * @return \Smile\ElasticsuiteThesaurus\Block\Adminhtml\Thesaurus\Edit\Form */ private function initBaseFields($fieldset, $model) { $fieldset->addField('name', 'text', ['name' => 'name', 'label' => __('Thesaurus Name'), 'title' => __('Thesaurus Name'), 'required' => true]); $fieldset->addField('is_active', 'select', ['name' => 'is_active', 'label' => __('Active'), 'title' => __('Active'), 'values' => $this->booleanSource->toOptionArray()]); if (!$this->_storeManager->isSingleStoreMode()) { $field = $fieldset->addField('store_id', 'multiselect', ['name' => 'stores[]', 'label' => __('Store'), 'title' => __('Store'), 'values' => $this->systemStore->getStoreValuesForForm(false, true), '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']); $model->setStoreIds([$this->_storeManager->getStore(true)->getId()]); } return $this; }
/** * Prepare form * * @return $this */ protected function _prepareForm() { /** @var \Mageplaza\Blog\Model\Post $post */ $post = $this->_coreRegistry->registry('mageplaza_blog_post'); $form = $this->_formFactory->create(); $form->setHtmlIdPrefix('post_'); $form->setFieldNameSuffix('post'); $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Post Information'), 'class' => 'fieldset-wide']); $fieldset->addType('image', 'Mageplaza\\Blog\\Block\\Adminhtml\\Post\\Helper\\Image'); if ($post->getId()) { $fieldset->addField('post_id', 'hidden', ['name' => 'post_id']); } $fieldset->addField('name', 'text', ['name' => 'name', 'label' => __('Name'), 'title' => __('Name'), 'required' => true, 'note' => __('Post name')]); $fieldset->addField('short_description', 'textarea', ['name' => 'short_description', 'label' => __('Short Description'), 'title' => __('Short Description'), 'note' => __('Short Description')]); $fieldset->addField('post_content', 'editor', ['name' => 'post_content', 'label' => __('Content'), 'title' => __('Content'), 'note' => __('Post Content'), 'config' => $this->wysiwygConfig->getConfig()]); $fieldset->addField('image', 'image', ['name' => 'image', 'label' => __('Image'), 'title' => __('Image'), 'note' => __('Featured image')]); $fieldset->addField('enabled', 'select', ['name' => 'enabled', 'label' => __('Enabled'), 'title' => __('Enabled'), 'values' => $this->booleanOptions->toOptionArray()]); $fieldset->addField('url_key', 'text', ['name' => 'url_key', 'label' => __('URL Key'), 'title' => __('URL Key')]); $fieldset->addField('in_rss', 'select', ['name' => 'in_rss', 'label' => __('In RSS'), 'title' => __('In RSS'), 'values' => $this->booleanOptions->toOptionArray()]); $fieldset->addField('allow_comment', 'select', ['name' => 'allow_comment', 'label' => __('Allow Comment'), 'title' => __('Allow Comment'), 'values' => $this->booleanOptions->toOptionArray()]); $fieldset->addField('meta_title', 'text', ['name' => 'meta_title', 'label' => __('Meta Title'), 'title' => __('Meta Title')]); $fieldset->addField('meta_description', 'textarea', ['name' => 'meta_description', 'label' => __('Meta Description'), 'title' => __('Meta Description')]); $fieldset->addField('meta_keywords', 'textarea', ['name' => 'meta_keywords', 'label' => __('Meta Keywords'), 'title' => __('Meta Keywords')]); $fieldset->addField('meta_robots', 'select', ['name' => 'meta_robots', 'label' => __('Meta Robots'), 'title' => __('Meta Robots'), 'values' => array_merge(['' => ''], $this->metaRobotsOptions->toOptionArray())]); $postData = $this->_session->getData('mageplaza_blog_post_data', true); if ($postData) { $post->addData($postData); } else { if (!$post->getId()) { $post->addData($post->getDefaultValues()); } } $form->addValues($post->getData()); $this->setForm($form); return parent::_prepareForm(); }
/** * Retrieve qty type select html * * @return string */ public function getQtyTypeSelectHtml() { $select = $this->getLayout()->createBlock('Magento\\Framework\\View\\Element\\Html\\Select')->setData(['id' => $this->getFieldId() . '_<%- data.index %>_can_change_qty', 'class' => 'select'])->setName($this->getFieldName() . '[<%- data.parentIndex %>][<%- data.index %>][selection_can_change_qty]')->setOptions($this->_yesno->toOptionArray()); return $select->getHtml(); }
/** * @return mixed */ public function getRequireSelectHtml() { $select = $this->getLayout()->createBlock('Magento\\Framework\\View\\Element\\Html\\Select')->setData(['id' => $this->getFieldId() . '_<%- data.id %>_is_require', 'class' => 'select'])->setName($this->getFieldName() . '[<%- data.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())->setClass('admin__control-select'); return $select->getHtml(); }
/** * Append spellchecking related fields. * * @param Fieldset $fieldset Target fieldset * * @return FrontPlugin */ private function addSearchFields(Fieldset $fieldset) { $fieldset->addField('search_weight', 'select', ['name' => 'search_weight', 'label' => __('Search Weight'), 'values' => $this->weightSource->getOptions()], 'is_searchable'); $fieldset->addField('is_used_in_spellcheck', 'select', ['name' => 'is_used_in_spellcheck', 'label' => __('Used in spellcheck'), 'values' => $this->booleanSource->toOptionArray()], 'search_weight'); return $this; }