Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Group.php
Go to the documentation of this file.
1 <?php
7 
9 use Magento\Framework\Module\Manager as ModuleManager;
13 
14 class Group implements GroupSourceInterface
15 {
19  protected $moduleManager;
20 
24  protected $groupRepository;
25 
30 
36  public function __construct(
37  ModuleManager $moduleManager,
40  ) {
41  $this->moduleManager = $moduleManager;
42  $this->groupRepository = $groupRepository;
43  $this->searchCriteriaBuilder = $searchCriteriaBuilder;
44  }
45 
51  public function toOptionArray()
52  {
53  if (!$this->moduleManager->isEnabled('Magento_Customer')) {
54  return [];
55  }
56  $customerGroups = [];
57  $customerGroups[] = [
58  'label' => __('ALL GROUPS'),
59  'value' => (string)GroupInterface::CUST_GROUP_ALL,
60  ];
61 
63  $groups = $this->groupRepository->getList($this->searchCriteriaBuilder->create());
64  foreach ($groups->getItems() as $group) {
65  $customerGroups[] = [
66  'label' => $group->getCode(),
67  'value' => $group->getId(),
68  ];
69  }
70 
71  return $customerGroups;
72  }
73 }
$group
Definition: sections.phtml:16
__()
Definition: __.php:13
__construct(ModuleManager $moduleManager, GroupRepositoryInterface $groupRepository, SearchCriteriaBuilder $searchCriteriaBuilder)
Definition: Group.php:36