AttributeOptions.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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\EavGraphQl\Model\Resolver\DataProvider;
  8. use Magento\Eav\Api\AttributeOptionManagementInterface;
  9. /**
  10. * Attribute Options data provider
  11. */
  12. class AttributeOptions
  13. {
  14. /**
  15. * @var AttributeOptionManagementInterface
  16. */
  17. private $optionManager;
  18. /**
  19. * @param AttributeOptionManagementInterface $optionManager
  20. */
  21. public function __construct(
  22. AttributeOptionManagementInterface $optionManager
  23. ) {
  24. $this->optionManager = $optionManager;
  25. }
  26. /**
  27. * @param int $entityType
  28. * @param string $attributeCode
  29. * @return array
  30. */
  31. public function getData(int $entityType, string $attributeCode): array
  32. {
  33. $options = $this->optionManager->getItems($entityType, $attributeCode);
  34. $optionsData = [];
  35. foreach ($options as $option) {
  36. // without empty option @see \Magento\Eav\Model\Entity\Attribute\Source\Table::getAllOptions
  37. if ($option->getValue() === '') {
  38. continue;
  39. }
  40. $optionsData[] = [
  41. 'label' => $option->getLabel(),
  42. 'value' => $option->getValue()
  43. ];
  44. }
  45. return $optionsData;
  46. }
  47. }