46 private $propertyLocker;
66 $this->_yesNo = $yesNo;
67 $this->_eavData = $eavData;
80 $attributeObject = $this->getAttributeObject();
82 $form = $this->_formFactory->create(
83 [
'data' => [
'id' =>
'edit_form',
'action' => $this->
getData(
'action'),
'method' =>
'post']]
86 $fieldset = $form->addFieldset(
88 [
'legend' =>
__(
'Advanced Attribute Properties'),
'collapsable' =>
true]
91 $yesno = $this->_yesNo->toOptionArray();
93 $validateClass = sprintf(
94 'validate-code validate-length maximum-length-%d',
95 \
Magento\Eav\Model\Entity\Attribute::ATTRIBUTE_CODE_MAX_LENGTH
101 'name' =>
'attribute_code',
102 'label' =>
__(
'Attribute Code'),
103 'title' =>
__(
'Attribute Code'),
105 'This is used internally. Make sure you don\'t use spaces or more than %1 symbols.',
106 \
Magento\Eav\Model\Entity\Attribute::ATTRIBUTE_CODE_MAX_LENGTH
108 'class' => $validateClass
113 'default_value_text',
116 'name' =>
'default_value_text',
117 'label' =>
__(
'Default Value'),
118 'title' =>
__(
'Default Value'),
119 'value' => $attributeObject->getDefaultValue()
124 'default_value_yesno',
127 'name' =>
'default_value_yesno',
128 'label' =>
__(
'Default Value'),
129 'title' =>
__(
'Default Value'),
131 'value' => $attributeObject->getDefaultValue()
135 $dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
137 'default_value_date',
140 'name' =>
'default_value_date',
141 'label' =>
__(
'Default Value'),
142 'title' =>
__(
'Default Value'),
143 'value' => $attributeObject->getDefaultValue(),
144 'date_format' => $dateFormat
149 'default_value_textarea',
152 'name' =>
'default_value_textarea',
153 'label' =>
__(
'Default Value'),
154 'title' =>
__(
'Default Value'),
155 'value' => $attributeObject->getDefaultValue()
163 'name' =>
'is_unique',
164 'label' =>
__(
'Unique Value'),
165 'title' =>
__(
'Unique Value (not shared with other products)'),
166 'note' =>
__(
'Not shared with other products.'),
175 'name' =>
'frontend_class',
176 'label' =>
__(
'Input Validation for Store Owner'),
177 'title' =>
__(
'Input Validation for Store Owner'),
178 'values' => $this->_eavData->getFrontendClasses($attributeObject->getEntityType()->getEntityTypeCode())
186 'name' =>
'is_used_in_grid',
187 'label' =>
__(
'Add to Column Options'),
188 'title' =>
__(
'Add to Column Options'),
190 'value' => $attributeObject->getData(
'is_used_in_grid') ?: 1,
191 'note' =>
__(
'Select "Yes" to add this attribute to the list of column options in the product grid.'),
196 'is_visible_in_grid',
199 'name' =>
'is_visible_in_grid',
200 'value' => $attributeObject->getData(
'is_visible_in_grid') ?: 1,
205 'is_filterable_in_grid',
208 'name' =>
'is_filterable_in_grid',
209 'label' =>
__(
'Use in Filter Options'),
210 'title' =>
__(
'Use in Filter Options'),
212 'value' => $attributeObject->getData(
'is_filterable_in_grid') ?: 1,
213 'note' =>
__(
'Select "Yes" to add this attribute to the list of filter options in the product grid.'),
217 if ($attributeObject->getId()) {
218 $form->getElement(
'attribute_code')->setDisabled(1);
219 if (!$attributeObject->getIsUserDefined()) {
220 $form->getElement(
'is_unique')->setDisabled(1);
225 \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE =>
__(
'Store View'),
226 \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE =>
__(
'Website'),
227 \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL =>
__(
'Global'),
230 if ($attributeObject->getAttributeCode() ==
'status' || $attributeObject->getAttributeCode() ==
'tax_class_id' 232 unset($scopes[\
Magento\Eav\Model\Entity\
Attribute\ScopedAttributeInterface::SCOPE_STORE]);
239 'name' =>
'is_global',
240 'label' =>
__(
'Scope'),
241 'title' =>
__(
'Scope'),
242 'note' =>
__(
'Declare attribute value saving scope.'),
248 $this->_eventManager->dispatch(
'product_attribute_form_build', [
'form' => $form]);
250 $form->getElement(
'is_global')->setDisabled(1);
253 $this->getPropertyLocker()->lock($form);
264 $this->
getForm()->addValues($this->getAttributeObject()->
getData());
265 return parent::_initFormValues();
273 private function getAttributeObject()
275 return $this->_coreRegistry->registry(
'entity_attribute');
283 private function getPropertyLocker()
285 if (
null === $this->propertyLocker) {
288 return $this->propertyLocker;
getData($key='', $index=null)
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Data\FormFactory $formFactory, Yesno $yesNo, Data $eavData, array $disableScopeChangeList=['sku'], array $data=[])