Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GroupActions.php
Go to the documentation of this file.
1 <?php
7 declare(strict_types=1);
8 
10 
16 
20 class GroupActions extends Column
21 {
25  const URL_PATH_EDIT = 'customer/group/edit';
26  const URL_PATH_DELETE = 'customer/group/delete';
27 
31  private $urlBuilder;
32 
36  private $escaper;
37 
48  public function __construct(
51  UrlInterface $urlBuilder,
52  Escaper $escaper,
53  array $components = [],
54  array $data = []
55  ) {
56  $this->urlBuilder = $urlBuilder;
57  $this->escaper = $escaper;
58  parent::__construct($context, $uiComponentFactory, $components, $data);
59  }
60 
67  public function prepareDataSource(array $dataSource)
68  {
69  if (isset($dataSource['data']['items'])) {
70  foreach ($dataSource['data']['items'] as & $item) {
71  if (isset($item['customer_group_id'])) {
72  $title = $this->escaper->escapeHtml($item['customer_group_code']);
73  $item[$this->getData('name')] = [
74  'edit' => [
75  'href' => $this->urlBuilder->getUrl(
76  static::URL_PATH_EDIT,
77  [
78  'id' => $item['customer_group_id']
79  ]
80  ),
81  'label' => __('Edit'),
82  ],
83  ];
84 
85  // hide delete action for 'NOT LOGGED IN' group
86  if ($item['customer_group_id'] == 0 && $item['customer_group_code']) {
87  continue;
88  }
89 
90  $item[$this->getData('name')]['delete'] = [
91  'href' => $this->urlBuilder->getUrl(
92  static::URL_PATH_DELETE,
93  [
94  'id' => $item['customer_group_id']
95  ]
96  ),
97  'label' => __('Delete'),
98  'confirm' => [
99  'title' => __('Delete %1', $title),
100  'message' => __('Are you sure you want to delete a %1 record?', $title)
101  ],
102  'post' => true
103  ];
104  }
105  }
106  }
107 
108  return $dataSource;
109  }
110 }
$title
Definition: default.phtml:14
__()
Definition: __.php:13
__construct(ContextInterface $context, UiComponentFactory $uiComponentFactory, UrlInterface $urlBuilder, Escaper $escaper, array $components=[], array $data=[])