Multiselect.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Model\Config\Source\Group;
  7. use Magento\Customer\Model\Customer\Attribute\Source\GroupSourceLoggedInOnlyInterface;
  8. use Magento\Customer\Api\GroupManagementInterface;
  9. use Magento\Framework\App\ObjectManager;
  10. class Multiselect implements \Magento\Framework\Option\ArrayInterface
  11. {
  12. /**
  13. * Customer groups options array
  14. *
  15. * @var null|array
  16. */
  17. protected $_options;
  18. /**
  19. * @deprecated 101.0.0
  20. * @var GroupManagementInterface
  21. */
  22. protected $_groupManagement;
  23. /**
  24. * @deprecated 101.0.0
  25. * @var \Magento\Framework\Convert\DataObject
  26. */
  27. protected $_converter;
  28. /**
  29. * @var GroupSourceLoggedInOnlyInterface
  30. */
  31. private $groupSourceLoggedInOnly;
  32. /**
  33. * @param GroupManagementInterface $groupManagement
  34. * @param \Magento\Framework\Convert\DataObject $converter
  35. * @param GroupSourceLoggedInOnlyInterface|null $groupSourceLoggedInOnly
  36. */
  37. public function __construct(
  38. GroupManagementInterface $groupManagement,
  39. \Magento\Framework\Convert\DataObject $converter,
  40. GroupSourceLoggedInOnlyInterface $groupSourceLoggedInOnly = null
  41. ) {
  42. $this->_groupManagement = $groupManagement;
  43. $this->_converter = $converter;
  44. $this->groupSourceLoggedInOnly = $groupSourceLoggedInOnly
  45. ?: ObjectManager::getInstance()->get(GroupSourceLoggedInOnlyInterface::class);
  46. }
  47. /**
  48. * Retrieve customer groups as array
  49. *
  50. * @return array
  51. */
  52. public function toOptionArray()
  53. {
  54. if (!$this->_options) {
  55. $this->_options = $this->groupSourceLoggedInOnly->toOptionArray();
  56. }
  57. return $this->_options;
  58. }
  59. }