Group.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Model\Customer\Attribute\Source;
  7. use Magento\Customer\Api\GroupManagementInterface;
  8. /**
  9. * Customer group attribute source
  10. *
  11. * @author Magento Core Team <core@magentocommerce.com>
  12. */
  13. class Group extends \Magento\Eav\Model\Entity\Attribute\Source\Table implements GroupSourceLoggedInOnlyInterface
  14. {
  15. /**
  16. * @var GroupManagementInterface
  17. */
  18. protected $_groupManagement;
  19. /**
  20. * @var \Magento\Framework\Convert\DataObject
  21. */
  22. protected $_converter;
  23. /**
  24. * @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory
  25. * @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory $attrOptionFactory
  26. * @param GroupManagementInterface $groupManagement
  27. * @param \Magento\Framework\Convert\DataObject $converter
  28. */
  29. public function __construct(
  30. \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory,
  31. \Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory $attrOptionFactory,
  32. GroupManagementInterface $groupManagement,
  33. \Magento\Framework\Convert\DataObject $converter
  34. ) {
  35. $this->_groupManagement = $groupManagement;
  36. $this->_converter = $converter;
  37. parent::__construct($attrOptionCollectionFactory, $attrOptionFactory);
  38. }
  39. /**
  40. * @inheritdoc
  41. */
  42. public function getAllOptions($withEmpty = true, $defaultValues = false)
  43. {
  44. if (!$this->_options) {
  45. $groups = $this->_groupManagement->getLoggedInGroups();
  46. $this->_options = $this->_converter->toOptionArray($groups, 'id', 'code');
  47. }
  48. return $this->_options;
  49. }
  50. }