/** * 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); }
public function testToOptionArray() { $expectedResult = [['value' => 'text', 'label' => 'Text Field'], ['value' => 'textarea', 'label' => 'Text Area'], ['value' => 'date', 'label' => 'Date'], ['value' => 'boolean', 'label' => 'Yes/No'], ['value' => 'multiselect', 'label' => 'Multiple Select'], ['value' => 'select', 'label' => 'Dropdown']]; $this->assertEquals($expectedResult, $this->model->toOptionArray()); }