‪TYPO3CMS  ‪main
AbstractProvider.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 
23 use TYPO3\CMS\Core\Imaging\IconSize;
26 
31 {
37  protected ‪$languageService;
38 
42  protected ‪$backendUser;
43 
47  protected ‪$clipboard;
48 
54  protected ‪$itemsConfiguration = [];
55 
61  protected ‪$disabledItems = [];
62 
68  protected ‪$table = '';
69 
73  protected ‪$identifier = '';
74 
80  protected ‪$context = '';
81 
82  public function ‪__construct()
83  {
84  $this->languageService = ‪$GLOBALS['LANG'];
85  $this->backendUser = ‪$GLOBALS['BE_USER'];
86  }
87 
88  public function ‪setContext(string ‪$table, string ‪$identifier, string ‪$context = ''): void
89  {
90  $this->table = ‪$table;
91  $this->identifier = ‪$identifier;
92  $this->context = ‪$context;
93  }
94 
98  protected function ‪initialize()
99  {
101  $this->‪initDisabledItems();
102  }
103 
108  public function ‪getPriority(): int
109  {
110  return 100;
111  }
112 
116  public function ‪canHandle(): bool
117  {
118  return false;
119  }
120 
124  protected function ‪initClipboard()
125  {
126  ‪$clipboard = GeneralUtility::makeInstance(Clipboard::class);
128  // This locks the clipboard to the Normal for this request.
130  // This removes all no longer existing elements
132  // This stores the changed clipboard data
134  $this->clipboard = ‪$clipboard;
135  }
136 
141  protected function ‪initDisabledItems()
142  {
143  if ($this->context) {
144  $tsConfigValue = $this->backendUser->getTSConfig()['options.']['contextMenu.']['table.'][$this->table . '.'][$this->context . '.']['disableItems'] ?? '';
145  } else {
146  $tsConfigValue = $this->backendUser->getTSConfig()['options.']['contextMenu.']['table.'][$this->table . '.']['disableItems'] ?? '';
147  }
148  $this->disabledItems = ‪GeneralUtility::trimExplode(',', $tsConfigValue, true);
149  }
150 
154  public function ‪addItems(array $items): array
155  {
156  $this->‪initialize();
157  $items += $this->‪prepareItems($this->itemsConfiguration);
158  return $items;
159  }
160 
164  protected function ‪prepareItems(array ‪$itemsConfiguration): array
165  {
166  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
167  $items = [];
168  foreach (‪$itemsConfiguration as $name => $configuration) {
169  $type = !empty($configuration['type']) ? $configuration['type'] : 'item';
170  if ($this->‪canRender($name, $type)) {
171  $items[$name] = [
172  'type' => $type,
173  'label' => !empty($configuration['label']) ? htmlspecialchars($this->languageService->sL($configuration['label'])) : '',
174  'icon' => !empty($configuration['iconIdentifier']) ? $iconFactory->getIcon($configuration['iconIdentifier'], IconSize::SMALL)->render() : '',
175  'additionalAttributes' => $this->‪getAdditionalAttributes($name),
176  'callbackAction' => !empty($configuration['callbackAction']) ? $configuration['callbackAction'] : '',
177  ];
178  if ($type === 'submenu') {
179  $items[$name]['childItems'] = $this->‪prepareItems($configuration['childItems']);
180  }
181  }
182  }
183  return $items;
184  }
185 
190  protected function ‪getAdditionalAttributes(string $itemName): array
191  {
192  return [];
193  }
194 
198  protected function ‪canRender(string $itemName, string $type): bool
199  {
200  return true;
201  }
202 
206  protected function ‪getIdentifier(): string
207  {
208  return '';
209  }
210 }
‪TYPO3\CMS\Backend\Clipboard\Clipboard
Definition: Clipboard.php:48
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider\__construct
‪__construct()
Definition: AbstractProvider.php:74
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider\$languageService
‪LanguageService $languageService
Definition: AbstractProvider.php:36
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider\addItems
‪addItems(array $items)
Definition: AbstractProvider.php:146
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider\$disabledItems
‪array $disabledItems
Definition: AbstractProvider.php:56
‪TYPO3\CMS\Backend\Clipboard\Clipboard\lockToNormal
‪lockToNormal()
Definition: Clipboard.php:130
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider\prepareItems
‪prepareItems(array $itemsConfiguration)
Definition: AbstractProvider.php:156
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider\$table
‪string $table
Definition: AbstractProvider.php:62
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider\initialize
‪initialize()
Definition: AbstractProvider.php:90
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider
Definition: AbstractProvider.php:31
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider\canHandle
‪canHandle()
Definition: AbstractProvider.php:108
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider\getPriority
‪getPriority()
Definition: AbstractProvider.php:100
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider\setContext
‪setContext(string $table, string $identifier, string $context='')
Definition: AbstractProvider.php:80
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider\$itemsConfiguration
‪array $itemsConfiguration
Definition: AbstractProvider.php:50
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider\canRender
‪canRender(string $itemName, string $type)
Definition: AbstractProvider.php:190
‪TYPO3\CMS\Backend\Clipboard\Clipboard\initializeClipboard
‪initializeClipboard(?ServerRequestInterface $request=null)
Definition: Clipboard.php:99
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\ProviderInterface
Definition: ProviderInterface.php:24
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider\$context
‪string $context
Definition: AbstractProvider.php:72
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Clipboard\Clipboard\endClipboard
‪endClipboard()
Definition: Clipboard.php:207
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider\getAdditionalAttributes
‪getAdditionalAttributes(string $itemName)
Definition: AbstractProvider.php:182
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider\getIdentifier
‪getIdentifier()
Definition: AbstractProvider.php:198
‪TYPO3\CMS\Backend\Clipboard\Clipboard\cleanCurrent
‪cleanCurrent()
Definition: Clipboard.php:665
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider\$identifier
‪string $identifier
Definition: AbstractProvider.php:66
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider\$backendUser
‪BackendUserAuthentication $backendUser
Definition: AbstractProvider.php:40
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider\initClipboard
‪initClipboard()
Definition: AbstractProvider.php:116
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders
Definition: AbstractProvider.php:18
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider\$clipboard
‪TYPO3 CMS Backend Clipboard Clipboard $clipboard
Definition: AbstractProvider.php:44
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider\initDisabledItems
‪initDisabledItems()
Definition: AbstractProvider.php:133
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode(string $delim, string $string, bool $removeEmptyValues=false, int $limit=0)
Definition: GeneralUtility.php:822