/
Inputtype.php
69 lines (61 loc) · 1.99 KB
/
Inputtype.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
/**
* Product attribute source input types
*/
namespace Magento\Catalog\Model\Product\Attribute\Source;
class Inputtype extends \Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype
{
/**
* Core registry
*
* @var \Magento\Framework\Registry
*/
protected $_coreRegistry = null;
/**
* Core event manager proxy
*
* @var \Magento\Framework\Event\ManagerInterface
*/
protected $_eventManager = null;
/**
* @param \Magento\Framework\Event\ManagerInterface $eventManager
* @param \Magento\Framework\Registry $coreRegistry
*/
public function __construct(\Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Framework\Registry $coreRegistry)
{
$this->_eventManager = $eventManager;
$this->_coreRegistry = $coreRegistry;
}
/**
* 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);
}
}