Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Front.php
Go to the documentation of this file.
1 <?php
13 
22 
27 class Front extends Generic
28 {
32  protected $_yesNo;
33 
37  private $propertyLocker;
38 
47  public function __construct(
48  Context $context,
50  FormFactory $formFactory,
51  Yesno $yesNo,
52  PropertyLocker $propertyLocker,
53  array $data = []
54  ) {
55  $this->_yesNo = $yesNo;
56  $this->propertyLocker = $propertyLocker;
57  parent::__construct($context, $registry, $formFactory, $data);
58  }
59 
65  protected function _prepareForm()
66  {
68  $attributeObject = $this->_coreRegistry->registry('entity_attribute');
69 
71  $form = $this->_formFactory->create(
72  ['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]
73  );
74 
75  $yesnoSource = $this->_yesNo->toOptionArray();
76 
77  $fieldset = $form->addFieldset(
78  'front_fieldset',
79  ['legend' => __('Storefront Properties'), 'collapsable' => $this->getRequest()->has('popup')]
80  );
81 
82  $fieldset->addField(
83  'is_searchable',
84  'select',
85  [
86  'name' => 'is_searchable',
87  'label' => __('Use in Search'),
88  'title' => __('Use in Search'),
89  'values' => $yesnoSource,
90  ]
91  );
92 
93  $fieldset->addField(
94  'is_visible_in_advanced_search',
95  'select',
96  [
97  'name' => 'is_visible_in_advanced_search',
98  'label' => __('Visible in Advanced Search'),
99  'title' => __('Visible in Advanced Search'),
100  'values' => $yesnoSource,
101  ]
102  );
103 
104  $fieldset->addField(
105  'is_comparable',
106  'select',
107  [
108  'name' => 'is_comparable',
109  'label' => __('Comparable on Storefront'),
110  'title' => __('Comparable on Storefront'),
111  'values' => $yesnoSource,
112  ]
113  );
114 
115  $this->_eventManager->dispatch('product_attribute_form_build_front_tab', ['form' => $form]);
116 
117  $fieldset->addField(
118  'is_used_for_promo_rules',
119  'select',
120  [
121  'name' => 'is_used_for_promo_rules',
122  'label' => __('Use for Promo Rule Conditions'),
123  'title' => __('Use for Promo Rule Conditions'),
124  'values' => $yesnoSource,
125  ]
126  );
127 
128  $fieldset->addField(
129  'is_html_allowed_on_front',
130  'select',
131  [
132  'name' => 'is_html_allowed_on_front',
133  'label' => __('Allow HTML Tags on Storefront'),
134  'title' => __('Allow HTML Tags on Storefront'),
135  'values' => $yesnoSource,
136  ]
137  );
138  if (!$attributeObject->getId() || $attributeObject->getIsWysiwygEnabled()) {
139  $attributeObject->setIsHtmlAllowedOnFront(1);
140  }
141 
142  $fieldset->addField(
143  'is_visible_on_front',
144  'select',
145  [
146  'name' => 'is_visible_on_front',
147  'label' => __('Visible on Catalog Pages on Storefront'),
148  'title' => __('Visible on Catalog Pages on Storefront'),
149  'values' => $yesnoSource
150  ]
151  );
152 
153  $fieldset->addField(
154  'used_in_product_listing',
155  'select',
156  [
157  'name' => 'used_in_product_listing',
158  'label' => __('Used in Product Listing'),
159  'title' => __('Used in Product Listing'),
160  'note' => __('Depends on design theme.'),
161  'values' => $yesnoSource
162  ]
163  );
164 
165  $fieldset->addField(
166  'used_for_sort_by',
167  'select',
168  [
169  'name' => 'used_for_sort_by',
170  'label' => __('Used for Sorting in Product Listing'),
171  'title' => __('Used for Sorting in Product Listing'),
172  'note' => __('Depends on design theme.'),
173  'values' => $yesnoSource
174  ]
175  );
176 
177  $this->_eventManager->dispatch(
178  'adminhtml_catalog_product_attribute_edit_frontend_prepare_form',
179  ['form' => $form, 'attribute' => $attributeObject]
180  );
181 
182  // define field dependencies
183  $this->setChild(
184  'form_after',
185  $this->getLayout()->createBlock(
186  \Magento\Backend\Block\Widget\Form\Element\Dependence::class
187  )->addFieldMap(
188  "is_html_allowed_on_front",
189  'html_allowed_on_front'
190  )->addFieldMap(
191  "frontend_input",
192  'frontend_input_type'
193  )->addFieldMap(
194  "is_searchable",
195  'searchable'
196  )->addFieldMap(
197  "is_visible_in_advanced_search",
198  'advanced_search'
199  )->addFieldDependence(
200  'advanced_search',
201  'searchable',
202  '1'
203  )
204  );
205 
206  $this->setForm($form);
207  $form->setValues($attributeObject->getData());
208  $this->propertyLocker->lock($form);
209  return parent::_prepareForm();
210  }
211 }
getData($key='', $index=null)
Definition: DataObject.php:119
__construct(Context $context, Registry $registry, FormFactory $formFactory, Yesno $yesNo, PropertyLocker $propertyLocker, array $data=[])
Definition: Front.php:47
setForm(\Magento\Framework\Data\Form $form)
Definition: Form.php:112
__()
Definition: __.php:13