‪TYPO3CMS  11.5
ModifyRecordListRecordActionsEvent.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 
27 {
28  private array ‪$actions;
29  private string ‪$table;
30  private array ‪$record;
32 
34  {
35  $this->actions = ‪$actions;
36  $this->table = ‪$table;
37  $this->record = ‪$record;
38  $this->recordList = ‪$recordList;
39  }
40 
57  public function ‪setAction(
58  string $action,
59  string $actionName = '',
60  string $group = '',
61  string $before = '',
62  string $after = ''
63  ): void {
64  // Only "primary" and "secondary" are valid, default to "secondary" otherwise
65  $group = in_array($group, ['primary', 'secondary'], true) ? $group : 'secondary';
66 
67  if ($actionName !== '') {
68  if ($before !== '' && $this->‪hasAction($before, $group)) {
69  $end = array_splice($this->actions[$group], (int)(array_search($before, array_keys($this->actions[$group]), true)));
70  $this->actions[$group] = array_merge($this->actions[$group], [$actionName => $action], $end);
71  } elseif ($after !== '' && $this->‪hasAction($after, $group)) {
72  $end = array_splice($this->actions[$group], (int)(array_search($after, array_keys($this->actions[$group]), true)) + 1);
73  $this->actions[$group] = array_merge($this->actions[$group], [$actionName => $action], $end);
74  } else {
75  $this->actions[$group][$actionName] = $action;
76  }
77  } else {
78  $this->actions[$group][] = $action;
79  }
80  }
81 
90  public function ‪hasAction(string $actionName, string $group = ''): bool
91  {
92  if (in_array($group, ['primary', 'secondary'], true)) {
93  return (bool)($this->actions[$group][$actionName] ?? false);
94  }
95 
96  return (bool)($this->actions['primary'][$actionName] ?? $this->actions['secondary'][$actionName] ?? false);
97  }
98 
108  public function ‪getAction(string $actionName, string $group = ''): ?string
109  {
110  if (in_array($group, ['primary', 'secondary'], true)) {
111  return $this->actions[$group][$actionName] ?? null;
112  }
113 
114  return $this->actions['primary'][$actionName] ?? $this->actions['secondary'][$actionName] ?? null;
115  }
116 
127  public function ‪removeAction(string $actionName, string $group = ''): bool
128  {
129  if (($this->actions[$group][$actionName] ?? false) && in_array($group, ['primary', 'secondary'], true)) {
130  unset($this->actions[$group][$actionName]);
131  return true;
132  }
133 
134  $actionRemoved = false;
135 
136  if ($this->actions['primary'][$actionName] ?? false) {
137  unset($this->actions['primary'][$actionName]);
138  $actionRemoved = true;
139  }
140 
141  if ($this->actions['secondary'][$actionName] ?? false) {
142  unset($this->actions['secondary'][$actionName]);
143  $actionRemoved = true;
144  }
145 
146  return $actionRemoved;
147  }
148 
155  public function ‪getActionGroup(string $group): ?array
156  {
157  return in_array($group, ['primary', 'secondary'], true) ? $this->actions[$group] : null;
158  }
159 
160  public function ‪setActions(array ‪$actions): void
161  {
162  $this->actions = ‪$actions;
163  }
164 
165  public function ‪getActions(): array
166  {
167  return ‪$this->actions;
168  }
169 
170  public function ‪getTable(): string
171  {
172  return ‪$this->table;
173  }
174 
175  public function ‪getRecord(): array
176  {
177  return ‪$this->record;
178  }
179 
187  {
188  return ‪$this->recordList;
189  }
190 }
‪TYPO3\CMS\Recordlist\Event\ModifyRecordListRecordActionsEvent\setActions
‪setActions(array $actions)
Definition: ModifyRecordListRecordActionsEvent.php:160
‪TYPO3\CMS\Recordlist\Event\ModifyRecordListRecordActionsEvent\hasAction
‪bool hasAction(string $actionName, string $group='')
Definition: ModifyRecordListRecordActionsEvent.php:90
‪TYPO3\CMS\Recordlist\Event\ModifyRecordListRecordActionsEvent\$table
‪string $table
Definition: ModifyRecordListRecordActionsEvent.php:29
‪TYPO3\CMS\Recordlist\Event\ModifyRecordListRecordActionsEvent\getAction
‪string null getAction(string $actionName, string $group='')
Definition: ModifyRecordListRecordActionsEvent.php:108
‪TYPO3\CMS\Recordlist\Event\ModifyRecordListRecordActionsEvent\getRecord
‪getRecord()
Definition: ModifyRecordListRecordActionsEvent.php:175
‪TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList
Definition: DatabaseRecordList.php:59
‪TYPO3\CMS\Recordlist\Event\ModifyRecordListRecordActionsEvent\$actions
‪array $actions
Definition: ModifyRecordListRecordActionsEvent.php:28
‪TYPO3\CMS\Recordlist\Event\ModifyRecordListRecordActionsEvent\__construct
‪__construct(array $actions, string $table, array $record, DatabaseRecordList $recordList)
Definition: ModifyRecordListRecordActionsEvent.php:33
‪TYPO3\CMS\Recordlist\Event\ModifyRecordListRecordActionsEvent\getRecordList
‪DatabaseRecordList getRecordList()
Definition: ModifyRecordListRecordActionsEvent.php:186
‪TYPO3\CMS\Recordlist\Event\ModifyRecordListRecordActionsEvent
Definition: ModifyRecordListRecordActionsEvent.php:27
‪TYPO3\CMS\Recordlist\Event\ModifyRecordListRecordActionsEvent\setAction
‪setAction(string $action, string $actionName='', string $group='', string $before='', string $after='')
Definition: ModifyRecordListRecordActionsEvent.php:57
‪TYPO3\CMS\Recordlist\Event\ModifyRecordListRecordActionsEvent\$record
‪array $record
Definition: ModifyRecordListRecordActionsEvent.php:30
‪TYPO3\CMS\Recordlist\Event\ModifyRecordListRecordActionsEvent\removeAction
‪bool removeAction(string $actionName, string $group='')
Definition: ModifyRecordListRecordActionsEvent.php:127
‪TYPO3\CMS\Recordlist\Event\ModifyRecordListRecordActionsEvent\getActions
‪getActions()
Definition: ModifyRecordListRecordActionsEvent.php:165
‪TYPO3\CMS\Recordlist\Event\ModifyRecordListRecordActionsEvent\getTable
‪getTable()
Definition: ModifyRecordListRecordActionsEvent.php:170
‪TYPO3\CMS\Recordlist\Event\ModifyRecordListRecordActionsEvent\getActionGroup
‪array null getActionGroup(string $group)
Definition: ModifyRecordListRecordActionsEvent.php:155
‪TYPO3\CMS\Recordlist\Event
Definition: ModifyRecordListHeaderColumnsEvent.php:18
‪TYPO3\CMS\Recordlist\Event\ModifyRecordListRecordActionsEvent\$recordList
‪DatabaseRecordList $recordList
Definition: ModifyRecordListRecordActionsEvent.php:31