55 */
66namespace Magento \Eav \Model \Entity ;
77
8+ use Magento \Eav \Model \ReservedAttributeCheckerInterface ;
89use Magento \Eav \Model \Validator \Attribute \Code as AttributeCodeValidator ;
910use Magento \Framework \Api \AttributeValueFactory ;
1011use Magento \Framework \App \ObjectManager ;
@@ -29,17 +30,17 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im
2930 * The value is defined as 60 because in the flat mode attribute code will be transformed into column name.
3031 * MySQL allows only 64 symbols in column name.
3132 */
32- const ATTRIBUTE_CODE_MAX_LENGTH = 60 ;
33+ public const ATTRIBUTE_CODE_MAX_LENGTH = 60 ;
3334
3435 /**
3536 * Min accepted length of an attribute code.
3637 */
37- const ATTRIBUTE_CODE_MIN_LENGTH = 1 ;
38+ public const ATTRIBUTE_CODE_MIN_LENGTH = 1 ;
3839
3940 /**
4041 * Tag to use for attributes caching.
4142 */
42- const CACHE_TAG = 'EAV_ATTRIBUTE ' ;
43+ public const CACHE_TAG = 'EAV_ATTRIBUTE ' ;
4344
4445 /**
4546 * Prefix of model events names
@@ -69,6 +70,9 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im
6970
7071 /**
7172 * @var \Magento\Catalog\Model\Product\ReservedAttributeList
73+ *
74+ * @deprecated Incorrect direct dependency on Product attribute.
75+ * @see \Magento\Eav\Model\Entity\Attribute::$reservedAttributeChecker
7276 */
7377 protected $ reservedAttributeList ;
7478
@@ -87,6 +91,11 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im
8791 */
8892 private $ attributeCodeValidator ;
8993
94+ /**
95+ * @var ReservedAttributeCheckerInterface|null
96+ */
97+ private $ reservedAttributeChecker ;
98+
9099 /**
91100 * @param \Magento\Framework\Model\Context $context
92101 * @param \Magento\Framework\Registry $registry
@@ -108,6 +117,7 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im
108117 * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
109118 * @param array $data
110119 * @param AttributeCodeValidator|null $attributeCodeValidator
120+ * @param ReservedAttributeCheckerInterface|null $reservedAttributeChecker
111121 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
112122 * @codeCoverageIgnore
113123 */
@@ -131,7 +141,8 @@ public function __construct(
131141 \Magento \Framework \Model \ResourceModel \AbstractResource $ resource = null ,
132142 \Magento \Framework \Data \Collection \AbstractDb $ resourceCollection = null ,
133143 array $ data = [],
134- AttributeCodeValidator $ attributeCodeValidator = null
144+ AttributeCodeValidator $ attributeCodeValidator = null ,
145+ ?ReservedAttributeCheckerInterface $ reservedAttributeChecker = null
135146 ) {
136147 parent ::__construct (
137148 $ context ,
@@ -157,6 +168,9 @@ public function __construct(
157168 $ this ->attributeCodeValidator = $ attributeCodeValidator ?: ObjectManager::getInstance ()->get (
158169 AttributeCodeValidator::class
159170 );
171+ $ this ->reservedAttributeChecker = $ reservedAttributeChecker ?: ObjectManager::getInstance ()->get (
172+ ReservedAttributeCheckerInterface::class
173+ );
160174 }
161175
162176 /**
@@ -251,7 +265,7 @@ public function beforeSave()
251265 }
252266
253267 // 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 )) {
255269 throw new LocalizedException (
256270 __ (
257271 'The attribute code \'%1 \' is reserved by system. Please try another attribute code ' ,
@@ -535,6 +549,7 @@ public function __wakeup()
535549 $ this ->_localeDate = $ objectManager ->get (\Magento \Framework \Stdlib \DateTime \TimezoneInterface::class);
536550 $ this ->_localeResolver = $ objectManager ->get (\Magento \Framework \Locale \ResolverInterface::class);
537551 $ this ->reservedAttributeList = $ objectManager ->get (\Magento \Catalog \Model \Product \ReservedAttributeList::class);
552+ $ this ->reservedAttributeChecker = $ objectManager ->get (ReservedAttributeCheckerInterface::class);
538553 $ this ->dateTimeFormatter = $ objectManager ->get (DateTimeFormatterInterface::class);
539554 }
540555
0 commit comments