‪TYPO3CMS  ‪main
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  public function ‪__construct(
29  private array $actions,
30  private readonly string $table,
31  private readonly array ‪$record,
32  private readonly ‪DatabaseRecordList $recordList
33  ) {}
34 
51  public function ‪setAction(
52  string $action,
53  string $actionName = '',
54  string $group = '',
55  string $before = '',
56  string $after = ''
57  ): void {
58  // Only "primary" and "secondary" are valid, default to "secondary" otherwise
59  $group = in_array($group, ['primary', 'secondary'], true) ? $group : 'secondary';
60 
61  if ($actionName !== '') {
62  if ($before !== '' && $this->‪hasAction($before, $group)) {
63  $end = array_splice($this->actions[$group], (int)(array_search($before, array_keys($this->actions[$group]), true)));
64  $this->actions[$group] = array_merge($this->actions[$group], [$actionName => $action], $end);
65  } elseif ($after !== '' && $this->‪hasAction($after, $group)) {
66  $end = array_splice($this->actions[$group], (int)(array_search($after, array_keys($this->actions[$group]), true)) + 1);
67  $this->actions[$group] = array_merge($this->actions[$group], [$actionName => $action], $end);
68  } else {
69  $this->actions[$group][$actionName] = $action;
70  }
71  } else {
72  $this->actions[$group][] = $action;
73  }
74  }
75 
80  public function ‪hasAction(string $actionName, string $group = ''): bool
81  {
82  if (in_array($group, ['primary', 'secondary'], true)) {
83  return (bool)($this->actions[$group][$actionName] ?? false);
84  }
85 
86  return (bool)($this->actions['primary'][$actionName] ?? $this->actions['secondary'][$actionName] ?? false);
87  }
88 
94  public function ‪getAction(string $actionName, string $group = ''): ?string
95  {
96  if (in_array($group, ['primary', 'secondary'], true)) {
97  return $this->actions[$group][$actionName] ?? null;
98  }
99 
100  return $this->actions['primary'][$actionName] ?? $this->actions['secondary'][$actionName] ?? null;
101  }
102 
111  public function ‪removeAction(string $actionName, string $group = ''): bool
112  {
113  if (($this->actions[$group][$actionName] ?? false) && in_array($group, ['primary', 'secondary'], true)) {
114  unset($this->actions[$group][$actionName]);
115  return true;
116  }
117 
118  $actionRemoved = false;
119 
120  if ($this->actions['primary'][$actionName] ?? false) {
121  unset($this->actions['primary'][$actionName]);
122  $actionRemoved = true;
123  }
124 
125  if ($this->actions['secondary'][$actionName] ?? false) {
126  unset($this->actions['secondary'][$actionName]);
127  $actionRemoved = true;
128  }
129 
130  return $actionRemoved;
131  }
132 
136  public function ‪getActionGroup(string $group): ?array
137  {
138  return in_array($group, ['primary', 'secondary'], true) ? $this->actions[$group] : null;
139  }
140 
141  public function ‪setActions(array $actions): void
142  {
143  $this->actions = $actions;
144  }
145 
146  public function ‪getActions(): array
147  {
148  return $this->actions;
149  }
150 
151  public function ‪getTable(): string
152  {
153  return $this->table;
154  }
155 
156  public function ‪getRecord(): array
157  {
158  return ‪$this->record;
159  }
160 
167  {
168  return $this->recordList;
169  }
170 }
‪TYPO3\CMS\Backend\RecordList\Event\ModifyRecordListRecordActionsEvent\hasAction
‪hasAction(string $actionName, string $group='')
Definition: ModifyRecordListRecordActionsEvent.php:80
‪TYPO3\CMS\Backend\RecordList\Event\ModifyRecordListRecordActionsEvent\setAction
‪setAction(string $action, string $actionName='', string $group='', string $before='', string $after='')
Definition: ModifyRecordListRecordActionsEvent.php:51
‪TYPO3\CMS\Backend\RecordList\Event\ModifyRecordListRecordActionsEvent\getActions
‪getActions()
Definition: ModifyRecordListRecordActionsEvent.php:146
‪TYPO3\CMS\Backend\RecordList\Event\ModifyRecordListRecordActionsEvent\removeAction
‪bool removeAction(string $actionName, string $group='')
Definition: ModifyRecordListRecordActionsEvent.php:111
‪TYPO3\CMS\Backend\RecordList\DatabaseRecordList
Definition: DatabaseRecordList.php:68
‪TYPO3\CMS\Backend\RecordList\Event\ModifyRecordListRecordActionsEvent\setActions
‪setActions(array $actions)
Definition: ModifyRecordListRecordActionsEvent.php:141
‪TYPO3\CMS\Backend\RecordList\Event
Definition: ModifyRecordListHeaderColumnsEvent.php:18
‪TYPO3\CMS\Backend\RecordList\Event\ModifyRecordListRecordActionsEvent\__construct
‪__construct(private array $actions, private readonly string $table, private readonly array $record, private readonly DatabaseRecordList $recordList)
Definition: ModifyRecordListRecordActionsEvent.php:28
‪TYPO3\CMS\Webhooks\Message\$record
‪identifier readonly int readonly array $record
Definition: PageModificationMessage.php:36
‪TYPO3\CMS\Backend\RecordList\Event\ModifyRecordListRecordActionsEvent\getRecordList
‪getRecordList()
Definition: ModifyRecordListRecordActionsEvent.php:166
‪TYPO3\CMS\Backend\RecordList\Event\ModifyRecordListRecordActionsEvent
Definition: ModifyRecordListRecordActionsEvent.php:27
‪TYPO3\CMS\Backend\RecordList\Event\ModifyRecordListRecordActionsEvent\getRecord
‪getRecord()
Definition: ModifyRecordListRecordActionsEvent.php:156
‪TYPO3\CMS\Backend\RecordList\Event\ModifyRecordListRecordActionsEvent\getAction
‪getAction(string $actionName, string $group='')
Definition: ModifyRecordListRecordActionsEvent.php:94
‪TYPO3\CMS\Backend\RecordList\Event\ModifyRecordListRecordActionsEvent\getActionGroup
‪getActionGroup(string $group)
Definition: ModifyRecordListRecordActionsEvent.php:136
‪TYPO3\CMS\Backend\RecordList\Event\ModifyRecordListRecordActionsEvent\getTable
‪getTable()
Definition: ModifyRecordListRecordActionsEvent.php:151