GetAllowedAddressAttributes.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\CustomerGraphQl\Model\Customer\Address;
  8. use Magento\Customer\Api\AddressMetadataManagementInterface;
  9. use Magento\Eav\Model\Config;
  10. use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
  11. /**
  12. * Get allowed address attributes
  13. */
  14. class GetAllowedAddressAttributes
  15. {
  16. /**
  17. * @var Config
  18. */
  19. private $eavConfig;
  20. /**
  21. * @param Config $eavConfig
  22. */
  23. public function __construct(Config $eavConfig)
  24. {
  25. $this->eavConfig = $eavConfig;
  26. }
  27. /**
  28. * Get allowed address attributes
  29. *
  30. * @return AbstractAttribute[]
  31. */
  32. public function execute(): array
  33. {
  34. $attributes = $this->eavConfig->getEntityAttributes(
  35. AddressMetadataManagementInterface::ENTITY_TYPE_ADDRESS
  36. );
  37. foreach ($attributes as $attributeCode => $attribute) {
  38. if (false === $attribute->getIsVisibleOnFront()) {
  39. unset($attributes[$attributeCode]);
  40. }
  41. }
  42. return $attributes;
  43. }
  44. }