Config.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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\Source;
  7. /**
  8. * Entity/Attribute/Model - attribute selection source from configuration
  9. *
  10. * this class should be abstract, but kept usual for legacy purposes
  11. *
  12. * @author Magento Core Team <core@magentocommerce.com>
  13. */
  14. class Config extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
  15. {
  16. /**
  17. * @var array
  18. */
  19. protected $_optionsData;
  20. /**
  21. * @param array $options
  22. * @codeCoverageIgnore
  23. */
  24. public function __construct(array $options)
  25. {
  26. $this->_optionsData = $options;
  27. }
  28. /**
  29. * Retrieve all options for the source from configuration
  30. *
  31. * @throws \Magento\Framework\Exception\LocalizedException
  32. * @return array
  33. */
  34. public function getAllOptions()
  35. {
  36. if ($this->_options === null) {
  37. $this->_options = [];
  38. if (empty($this->_optionsData)) {
  39. throw new \Magento\Framework\Exception\LocalizedException(__('No options found.'));
  40. }
  41. foreach ($this->_optionsData as $option) {
  42. $this->_options[] = ['value' => $option['value'], 'label' => __($option['label'])];
  43. }
  44. }
  45. return $this->_options;
  46. }
  47. }