‪TYPO3CMS  ‪main
ModifyNewContentElementWizardItemsEvent.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 
24 {
25  public function ‪__construct(
26  private array $wizardItems,
27  private readonly array $pageInfo,
28  private readonly int|null $colPos,
29  private readonly int $sys_language,
30  private readonly int $uid_pid,
31  ) {}
32 
33  public function ‪getWizardItems(): array
34  {
35  return $this->wizardItems;
36  }
37 
38  public function ‪setWizardItems(array $wizardItems): void
39  {
40  $this->wizardItems = $wizardItems;
41  }
42 
43  public function ‪hasWizardItem(string ‪$identifier): bool
44  {
45  return isset($this->wizardItems[‪$identifier]);
46  }
47 
48  public function ‪getWizardItem(string ‪$identifier): ?array
49  {
50  return $this->wizardItems[‪$identifier] ?? null;
51  }
52 
57  public function ‪setWizardItem(string ‪$identifier, array $configuration, array $position = []): void
58  {
59  if (isset($this->wizardItems[$position['before'] ?? null])
60  || isset($this->wizardItems[$position['after'] ?? null])
61  ) {
62  // Always unset an existing item if valid positioning is requested
63  unset($this->wizardItems[‪$identifier]);
64  }
65 
66  // Add item before another item
67  if (($position['before'] ?? false)
68  && ($insertPosition = array_search((string)$position['before'], array_keys($this->wizardItems), true)) !== false
69  ) {
70  $this->wizardItems = array_slice($this->wizardItems, 0, $insertPosition)
71  + [‪$identifier => $configuration]
72  + array_slice($this->wizardItems, $insertPosition);
73  return;
74  }
75 
76  // Add item after another item
77  if (($position['after'] ?? false)
78  && ($insertPosition = array_search((string)$position['after'], array_keys($this->wizardItems), true)) !== false
79  ) {
80  $this->wizardItems = array_slice($this->wizardItems, 0, $insertPosition + 1)
81  + [‪$identifier => $configuration]
82  + array_slice($this->wizardItems, $insertPosition + 1);
83  return;
84  }
85 
86  // By default, add the item at the bottom or might just overwrite configuration of an existing item
87  $this->wizardItems[‪$identifier] = $configuration;
88  }
89 
90  public function ‪removeWizardItem(string ‪$identifier): bool
91  {
92  if (!$this->‪hasWizardItem($identifier)) {
93  return false;
94  }
95 
96  unset($this->wizardItems[‪$identifier]);
97  return true;
98  }
99 
103  public function ‪getPageInfo(): array
104  {
105  return $this->pageInfo;
106  }
107 
111  public function ‪getColPos(): ?int
112  {
113  return $this->colPos;
114  }
115 
119  public function ‪getSysLanguage(): int
120  {
121  return $this->sys_language;
122  }
123 
127  public function ‪getUidPid(): int
128  {
129  return $this->uid_pid;
130  }
131 }
‪TYPO3\CMS\Backend\Controller\Event\ModifyNewContentElementWizardItemsEvent
Definition: ModifyNewContentElementWizardItemsEvent.php:24
‪TYPO3\CMS\Backend\Controller\Event\ModifyNewContentElementWizardItemsEvent\getSysLanguage
‪getSysLanguage()
Definition: ModifyNewContentElementWizardItemsEvent.php:119
‪TYPO3\CMS\Backend\Controller\Event
Definition: AfterBackendPageRenderEvent.php:18
‪TYPO3\CMS\Backend\Controller\Event\ModifyNewContentElementWizardItemsEvent\removeWizardItem
‪removeWizardItem(string $identifier)
Definition: ModifyNewContentElementWizardItemsEvent.php:90
‪TYPO3\CMS\Backend\Controller\Event\ModifyNewContentElementWizardItemsEvent\getWizardItems
‪getWizardItems()
Definition: ModifyNewContentElementWizardItemsEvent.php:33
‪TYPO3\CMS\Backend\Controller\Event\ModifyNewContentElementWizardItemsEvent\hasWizardItem
‪hasWizardItem(string $identifier)
Definition: ModifyNewContentElementWizardItemsEvent.php:43
‪TYPO3\CMS\Backend\Controller\Event\ModifyNewContentElementWizardItemsEvent\getUidPid
‪getUidPid()
Definition: ModifyNewContentElementWizardItemsEvent.php:127
‪TYPO3\CMS\Backend\Controller\Event\ModifyNewContentElementWizardItemsEvent\setWizardItems
‪setWizardItems(array $wizardItems)
Definition: ModifyNewContentElementWizardItemsEvent.php:38
‪TYPO3\CMS\Backend\Controller\Event\ModifyNewContentElementWizardItemsEvent\__construct
‪__construct(private array $wizardItems, private readonly array $pageInfo, private readonly int|null $colPos, private readonly int $sys_language, private readonly int $uid_pid,)
Definition: ModifyNewContentElementWizardItemsEvent.php:25
‪TYPO3\CMS\Backend\Controller\Event\ModifyNewContentElementWizardItemsEvent\getPageInfo
‪getPageInfo()
Definition: ModifyNewContentElementWizardItemsEvent.php:103
‪TYPO3\CMS\Backend\Controller\Event\ModifyNewContentElementWizardItemsEvent\setWizardItem
‪setWizardItem(string $identifier, array $configuration, array $position=[])
Definition: ModifyNewContentElementWizardItemsEvent.php:57
‪TYPO3\CMS\Backend\Controller\Event\ModifyNewContentElementWizardItemsEvent\getColPos
‪getColPos()
Definition: ModifyNewContentElementWizardItemsEvent.php:111
‪TYPO3\CMS\Backend\Controller\Event\ModifyNewContentElementWizardItemsEvent\getWizardItem
‪getWizardItem(string $identifier)
Definition: ModifyNewContentElementWizardItemsEvent.php:48
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37