/
Create.php
111 lines (100 loc) · 2.85 KB
/
Create.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* New attribute panel on product edit page
*
* @author Magento Core Team <core@magentocommerce.com>
*/
namespace Magento\Catalog\Block\Adminhtml\Product\Edit\Tab\Attributes;
use Magento\Backend\Block\Widget\Button;
class Create extends Button
{
/**
* Config of create new attribute
*
* @var \Magento\Framework\DataObject
*/
protected $_config = null;
/**
* Retrieve config of new attribute creation
*
* @return \Magento\Framework\DataObject
*/
public function getConfig()
{
if ($this->_config === null) {
$this->_config = new \Magento\Framework\DataObject();
}
return $this->_config;
}
/**
* @return $this
*/
protected function _beforeToHtml()
{
$this->setId(
'create_attribute_' . $this->getConfig()->getGroupId()
)->setType(
'button'
)->setClass(
'action-add'
)->setLabel(
__('New Attribute')
)->setDataAttribute(
[
'mage-init' => [
'productAttributes' => [
'url' => $this->getUrl(
'catalog/product_attribute/new',
[
'group' => $this->getConfig()->getAttributeGroupCode(),
'store' => $this->getConfig()->getStoreId(),
'product' => $this->getConfig()->getProductId(),
'type' => $this->getConfig()->getTypeId(),
'popup' => 1
]
),
],
],
]
);
$this->getConfig()->setUrl(
$this->getUrl(
'catalog/product_attribute/new',
[
'group' => $this->getConfig()->getAttributeGroupCode(),
'store' => $this->getConfig()->getStoreId(),
'product' => $this->getConfig()->getProductId(),
'type' => $this->getConfig()->getTypeId(),
'popup' => 1
]
)
);
return parent::_beforeToHtml();
}
/**
* @return string
*/
protected function _toHtml()
{
$this->setCanShow(true);
$this->_eventManager->dispatch(
'adminhtml_catalog_product_edit_tab_attributes_create_html_before',
['block' => $this]
);
if (!$this->getCanShow()) {
return '';
}
return parent::_toHtml();
}
/**
* @return string
*/
public function getJsObjectName()
{
return $this->getId() . 'JsObject';
}
}