/
Attributes.php
88 lines (75 loc) · 2.59 KB
/
Attributes.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Product attributes tab
*
* @author Magento Core Team <core@magentocommerce.com>
*/
namespace Magento\Catalog\Block\Adminhtml\Product\Attribute\NewAttribute\Product;
use Magento\Backend\Block\Widget\Form;
/**
* @SuppressWarnings(PHPMD.DepthOfInheritance)
*/
class Attributes extends \Magento\Catalog\Block\Adminhtml\Form
{
/**
* @return void
*/
protected function _prepareForm()
{
/** @var \Magento\Framework\Data\Form $form */
$form = $this->_formFactory->create();
/**
* Initialize product object as form property
* for using it in elements generation
*/
$form->setDataObject($this->_coreRegistry->registry('product'));
$fieldset = $form->addFieldset('group_fields', []);
$attributes = $this->getGroupAttributes();
$this->_setFieldset($attributes, $fieldset, ['gallery']);
$values = $this->_coreRegistry->registry('product')->getData();
/**
* Set attribute default values for new product
*/
if (!$this->_coreRegistry->registry('product')->getId()) {
foreach ($attributes as $attribute) {
if (!isset($values[$attribute->getAttributeCode()])) {
$values[$attribute->getAttributeCode()] = $attribute->getDefaultValue();
}
}
}
$this->_eventManager->dispatch('adminhtml_catalog_product_edit_prepare_form', ['form' => $form]);
$form->addValues($values);
$form->setFieldNameSuffix('product');
$this->setForm($form);
}
/**
* @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;
}
/**
* @return string
*/
protected function _toHtml()
{
parent::_toHtml();
return $this->getForm()->getElement('group_fields')->getChildrenHtml();
}
}