-
Notifications
You must be signed in to change notification settings - Fork 1
/
Attribute.php
133 lines (122 loc) · 4.09 KB
/
Attribute.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* Catalog product attribute controller
*/
namespace Magento\Catalog\Controller\Adminhtml\Product;
use Magento\Framework\Controller\Result;
use Magento\Framework\View\Result\PageFactory;
abstract class Attribute extends \Magento\Backend\App\Action
{
/**
* Authorization level of a basic admin session
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Magento_Catalog::attributes_attributes';
/**
* @var \Magento\Framework\Cache\FrontendInterface
*/
protected $_attributeLabelCache;
/**
* @var string
*/
protected $_entityTypeId;
/**
* Core registry
*
* @var \Magento\Framework\Registry
*/
protected $_coreRegistry = null;
/**
* @var \Magento\Framework\View\Result\PageFactory
*/
protected $resultPageFactory;
/**
* Constructor
*
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\Cache\FrontendInterface $attributeLabelCache
* @param \Magento\Framework\Registry $coreRegistry
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\Cache\FrontendInterface $attributeLabelCache,
\Magento\Framework\Registry $coreRegistry,
PageFactory $resultPageFactory
) {
$this->_coreRegistry = $coreRegistry;
$this->_attributeLabelCache = $attributeLabelCache;
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
}
/**
* Dispatch request
*
* @param \Magento\Framework\App\RequestInterface $request
* @return \Magento\Framework\App\ResponseInterface
*/
public function dispatch(\Magento\Framework\App\RequestInterface $request)
{
$this->_entityTypeId = $this->_objectManager->create(
'Magento\Eav\Model\Entity'
)->setType(
\Magento\Catalog\Model\Product::ENTITY
)->getTypeId();
return parent::dispatch($request);
}
/**
* @param \Magento\Framework\Phrase|null $title
* @return \Magento\Backend\Model\View\Result\Page
*/
protected function createActionPage($title = null)
{
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
$resultPage = $this->resultPageFactory->create();
if ($this->getRequest()->getParam('popup')) {
if ($this->getRequest()->getParam('product_tab') === 'variations') {
$resultPage->addHandle(['popup', 'catalog_product_attribute_edit_product_tab_variations_popup']);
} else {
$resultPage->addHandle(['popup', 'catalog_product_attribute_edit_popup']);
}
$pageConfig = $resultPage->getConfig();
$pageConfig->addBodyClass('attribute-popup');
} else {
$resultPage->addBreadcrumb(__('Catalog'), __('Catalog'))
->addBreadcrumb(__('Manage Product Attributes'), __('Manage Product Attributes'))
->setActiveMenu('Magento_Catalog::catalog_attributes_attributes');
if (!empty($title)) {
$resultPage->addBreadcrumb($title, $title);
}
}
$resultPage->getConfig()->getTitle()->prepend(__('Product Attributes'));
return $resultPage;
}
/**
* Generate code from label
*
* @param string $label
* @return string
*/
protected function generateCode($label)
{
$code = substr(
preg_replace(
'/[^a-z_0-9]/',
'_',
$this->_objectManager->create('Magento\Catalog\Model\Product\Url')->formatUrlKey($label)
),
0,
30
);
$validatorAttrCode = new \Zend_Validate_Regex(['pattern' => '/^[a-z][a-z_0-9]{0,29}[a-z0-9]$/']);
if (!$validatorAttrCode->isValid($code)) {
$code = 'attr_' . ($code ?: substr(md5(time()), 0, 8));
}
return $code;
}
}