Config.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Eav\Model\Entity\Attribute;
  7. use Magento\Framework\Serialize\SerializerInterface;
  8. /**
  9. * Provides EAV attributes configuration
  10. *
  11. * @api
  12. * @since 100.0.2
  13. */
  14. class Config extends \Magento\Framework\Config\Data
  15. {
  16. /**
  17. * Constructor
  18. *
  19. * @param Config\Reader $reader
  20. * @param \Magento\Framework\Config\CacheInterface $cache
  21. * @param string|null $cacheId
  22. * @param SerializerInterface|null $serializer
  23. */
  24. public function __construct(
  25. \Magento\Eav\Model\Entity\Attribute\Config\Reader $reader,
  26. \Magento\Framework\Config\CacheInterface $cache,
  27. $cacheId = 'eav_attributes',
  28. SerializerInterface $serializer = null
  29. ) {
  30. parent::__construct($reader, $cache, $cacheId, $serializer);
  31. }
  32. /**
  33. * Retrieve list of locked fields for attribute
  34. *
  35. * @param AbstractAttribute $attribute
  36. * @return array
  37. */
  38. public function getLockedFields(AbstractAttribute $attribute)
  39. {
  40. $allFields = $this->get(
  41. $attribute->getEntityType()->getEntityTypeCode() . '/attributes/' . $attribute->getAttributeCode()
  42. );
  43. if (!is_array($allFields)) {
  44. return [];
  45. }
  46. $lockedFields = [];
  47. foreach (array_keys($allFields) as $fieldCode) {
  48. $lockedFields[$fieldCode] = $fieldCode;
  49. }
  50. return $lockedFields;
  51. }
  52. /**
  53. * Retrieve attributes list with config for entity
  54. *
  55. * @param string $entityCode
  56. * @return array
  57. */
  58. public function getEntityAttributesLockedFields($entityCode)
  59. {
  60. $lockedFields = [];
  61. $entityAttributes = $this->get($entityCode . '/attributes');
  62. foreach ($entityAttributes as $attributeCode => $attributeData) {
  63. foreach ($attributeData as $attributeField) {
  64. if ($attributeField['locked']) {
  65. $lockedFields[$attributeCode][] = $attributeField['code'];
  66. }
  67. }
  68. }
  69. return $lockedFields;
  70. }
  71. }