/** * @return array */ protected function _getAdditionalElementTypes() { $result = ['price' => 'Magento\\Catalog\\Block\\Adminhtml\\Product\\Helper\\Form\\Price', 'image' => 'Magento\\Catalog\\Block\\Adminhtml\\Product\\Helper\\Form\\Image', 'boolean' => 'Magento\\Catalog\\Block\\Adminhtml\\Product\\Helper\\Form\\Boolean']; $response = new \Magento\Framework\DataObject(); $response->setTypes([]); $this->_eventManager->dispatch('adminhtml_catalog_product_edit_element_types', ['response' => $response]); foreach ($response->getTypes() as $typeName => $typeClass) { $result[$typeName] = $typeClass; } return $result; }
/** * Get product input types as option array * * @return array * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function toOptionArray() { $inputTypes = [['value' => 'price', 'label' => __('Price')], ['value' => 'media_image', 'label' => __('Media Image')]]; $response = new \Magento\Framework\DataObject(); $response->setTypes([]); $this->_eventManager->dispatch('adminhtml_product_attribute_types', ['response' => $response]); $_hiddenFields = []; foreach ($response->getTypes() as $type) { $inputTypes[] = $type; if (isset($type['hide_fields'])) { $_hiddenFields[$type['value']] = $type['hide_fields']; } } if ($this->_coreRegistry->registry('attribute_type_hidden_fields') === null) { $this->_coreRegistry->register('attribute_type_hidden_fields', $_hiddenFields); } return array_merge(parent::toOptionArray(), $inputTypes); }
/** * Adding product form elements for editing attribute * * @return $this * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ protected function _prepareForm() { parent::_prepareForm(); /** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attributeObject */ $attributeObject = $this->getAttributeObject(); /* @var $form \Magento\Framework\Data\Form */ $form = $this->getForm(); /* @var $fieldset \Magento\Framework\Data\Form\Element\Fieldset */ $fieldset = $form->getElement('base_fieldset'); $fiedsToRemove = ['attribute_code', 'is_unique', 'frontend_class']; foreach ($fieldset->getElements() as $element) { /** @var \Magento\Framework\Data\Form\AbstractForm $element */ if (substr($element->getId(), 0, strlen('default_value')) == 'default_value') { $fiedsToRemove[] = $element->getId(); } } foreach ($fiedsToRemove as $id) { $fieldset->removeField($id); } $frontendInputElm = $form->getElement('frontend_input'); $additionalTypes = [['value' => 'price', 'label' => __('Price')], ['value' => 'media_image', 'label' => __('Media Image')]]; $additionalReadOnlyTypes = ['gallery' => __('Gallery')]; if (isset($additionalReadOnlyTypes[$attributeObject->getFrontendInput()])) { $additionalTypes[] = ['value' => $attributeObject->getFrontendInput(), 'label' => $additionalReadOnlyTypes[$attributeObject->getFrontendInput()]]; } $response = new \Magento\Framework\DataObject(); $response->setTypes([]); $this->_eventManager->dispatch('adminhtml_product_attribute_types', ['response' => $response]); $_hiddenFields = []; foreach ($response->getTypes() as $type) { $additionalTypes[] = $type; if (isset($type['hide_fields'])) { $_hiddenFields[$type['value']] = $type['hide_fields']; } } $this->_coreRegistry->register('attribute_type_hidden_fields', $_hiddenFields); $this->_eventManager->dispatch('product_attribute_form_build_main_tab', ['form' => $form]); $frontendInputValues = array_merge($frontendInputElm->getValues(), $additionalTypes); $frontendInputElm->setValues($frontendInputValues); return $this; }