5
5
*/
6
6
namespace Magento \Eav \Model \Entity ;
7
7
8
+ use Magento \Eav \Model \ReservedAttributeCheckerInterface ;
8
9
use Magento \Eav \Model \Validator \Attribute \Code as AttributeCodeValidator ;
9
10
use Magento \Framework \Api \AttributeValueFactory ;
10
11
use Magento \Framework \App \ObjectManager ;
@@ -29,17 +30,17 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im
29
30
* The value is defined as 60 because in the flat mode attribute code will be transformed into column name.
30
31
* MySQL allows only 64 symbols in column name.
31
32
*/
32
- const ATTRIBUTE_CODE_MAX_LENGTH = 60 ;
33
+ public const ATTRIBUTE_CODE_MAX_LENGTH = 60 ;
33
34
34
35
/**
35
36
* Min accepted length of an attribute code.
36
37
*/
37
- const ATTRIBUTE_CODE_MIN_LENGTH = 1 ;
38
+ public const ATTRIBUTE_CODE_MIN_LENGTH = 1 ;
38
39
39
40
/**
40
41
* Tag to use for attributes caching.
41
42
*/
42
- const CACHE_TAG = 'EAV_ATTRIBUTE ' ;
43
+ public const CACHE_TAG = 'EAV_ATTRIBUTE ' ;
43
44
44
45
/**
45
46
* Prefix of model events names
@@ -69,6 +70,9 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im
69
70
70
71
/**
71
72
* @var \Magento\Catalog\Model\Product\ReservedAttributeList
73
+ *
74
+ * @deprecated Incorrect direct dependency on Product attribute.
75
+ * @see \Magento\Eav\Model\Entity\Attribute::$reservedAttributeChecker
72
76
*/
73
77
protected $ reservedAttributeList ;
74
78
@@ -87,6 +91,11 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im
87
91
*/
88
92
private $ attributeCodeValidator ;
89
93
94
+ /**
95
+ * @var ReservedAttributeCheckerInterface|null
96
+ */
97
+ private $ reservedAttributeChecker ;
98
+
90
99
/**
91
100
* @param \Magento\Framework\Model\Context $context
92
101
* @param \Magento\Framework\Registry $registry
@@ -108,6 +117,7 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im
108
117
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
109
118
* @param array $data
110
119
* @param AttributeCodeValidator|null $attributeCodeValidator
120
+ * @param ReservedAttributeCheckerInterface|null $reservedAttributeChecker
111
121
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
112
122
* @codeCoverageIgnore
113
123
*/
@@ -131,7 +141,8 @@ public function __construct(
131
141
\Magento \Framework \Model \ResourceModel \AbstractResource $ resource = null ,
132
142
\Magento \Framework \Data \Collection \AbstractDb $ resourceCollection = null ,
133
143
array $ data = [],
134
- AttributeCodeValidator $ attributeCodeValidator = null
144
+ AttributeCodeValidator $ attributeCodeValidator = null ,
145
+ ?ReservedAttributeCheckerInterface $ reservedAttributeChecker = null
135
146
) {
136
147
parent ::__construct (
137
148
$ context ,
@@ -157,6 +168,9 @@ public function __construct(
157
168
$ this ->attributeCodeValidator = $ attributeCodeValidator ?: ObjectManager::getInstance ()->get (
158
169
AttributeCodeValidator::class
159
170
);
171
+ $ this ->reservedAttributeChecker = $ reservedAttributeChecker ?: ObjectManager::getInstance ()->get (
172
+ ReservedAttributeCheckerInterface::class
173
+ );
160
174
}
161
175
162
176
/**
@@ -251,7 +265,7 @@ public function beforeSave()
251
265
}
252
266
253
267
// prevent overriding product data
254
- if (isset ($ this ->_data ['attribute_code ' ]) && $ this ->reservedAttributeList ->isReservedAttribute ($ this )) {
268
+ if (isset ($ this ->_data ['attribute_code ' ]) && $ this ->reservedAttributeChecker ->isReservedAttribute ($ this )) {
255
269
throw new LocalizedException (
256
270
__ (
257
271
'The attribute code \'%1 \' is reserved by system. Please try another attribute code ' ,
@@ -535,6 +549,7 @@ public function __wakeup()
535
549
$ this ->_localeDate = $ objectManager ->get (\Magento \Framework \Stdlib \DateTime \TimezoneInterface::class);
536
550
$ this ->_localeResolver = $ objectManager ->get (\Magento \Framework \Locale \ResolverInterface::class);
537
551
$ this ->reservedAttributeList = $ objectManager ->get (\Magento \Catalog \Model \Product \ReservedAttributeList::class);
552
+ $ this ->reservedAttributeChecker = $ objectManager ->get (ReservedAttributeCheckerInterface::class);
538
553
$ this ->dateTimeFormatter = $ objectManager ->get (DateTimeFormatterInterface::class);
539
554
}
540
555
0 commit comments