Group.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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;
  7. use Magento\Customer\Api\GroupManagementInterface;
  8. use Magento\Customer\Model\Customer\Attribute\Source\GroupSourceLoggedInOnlyInterface;
  9. use Magento\Framework\App\ObjectManager;
  10. class Group implements \Magento\Framework\Option\ArrayInterface
  11. {
  12. /**
  13. * @var array
  14. */
  15. protected $_options;
  16. /**
  17. * @deprecated 101.0.0
  18. * @var GroupManagementInterface
  19. */
  20. protected $_groupManagement;
  21. /**
  22. * @deprecated 101.0.0
  23. * @var \Magento\Framework\Convert\DataObject
  24. */
  25. protected $_converter;
  26. /**
  27. * @var GroupSourceLoggedInOnlyInterface
  28. */
  29. private $groupSourceLoggedInOnly;
  30. /**
  31. * @param GroupManagementInterface $groupManagement
  32. * @param \Magento\Framework\Convert\DataObject $converter
  33. * @param GroupSourceLoggedInOnlyInterface $groupSourceForLoggedInCustomers
  34. */
  35. public function __construct(
  36. GroupManagementInterface $groupManagement,
  37. \Magento\Framework\Convert\DataObject $converter,
  38. GroupSourceLoggedInOnlyInterface $groupSourceForLoggedInCustomers = null
  39. ) {
  40. $this->_groupManagement = $groupManagement;
  41. $this->_converter = $converter;
  42. $this->groupSourceLoggedInOnly = $groupSourceForLoggedInCustomers
  43. ?: ObjectManager::getInstance()->get(GroupSourceLoggedInOnlyInterface::class);
  44. }
  45. /**
  46. * @inheritdoc
  47. */
  48. public function toOptionArray()
  49. {
  50. if (!$this->_options) {
  51. $this->_options = $this->groupSourceLoggedInOnly->toOptionArray();
  52. array_unshift($this->_options, ['value' => '', 'label' => __('-- Please Select --')]);
  53. }
  54. return $this->_options;
  55. }
  56. }