TYPO3 CMS  TYPO3_8-7
AbstractProvider.php
Go to the documentation of this file.
1 <?php
2 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 
24 
29 {
30 
36  protected $languageService;
37 
41  protected $backendUser;
42 
46  protected $clipboard;
47 
53  protected $itemsConfiguration = [];
54 
60  protected $disabledItems = [];
61 
67  protected $table = '';
68 
72  protected $identifier = '';
73 
79  protected $context = '';
80 
89  public function __construct(string $table, string $identifier, string $context='')
90  {
91  $this->table = $table;
92  $this->identifier = $identifier;
93  $this->context = $context;
94  $this->languageService = $GLOBALS['LANG'];
95  $this->backendUser = $GLOBALS['BE_USER'];
96  }
97 
101  protected function initialize()
102  {
103  $this->initClipboard();
104  $this->initDisabledItems();
105  }
106 
113  public function getPriority(): int
114  {
115  return 100;
116  }
117 
123  public function canHandle(): bool
124  {
125  return false;
126  }
127 
131  protected function initClipboard()
132  {
133  $clipboard = GeneralUtility::makeInstance(Clipboard::class);
134  $clipboard->initializeClipboard();
135  // This locks the clipboard to the Normal for this request.
136  $clipboard->lockToNormal();
137  $this->clipboard = $clipboard;
138  }
139 
144  protected function initDisabledItems()
145  {
146  $TSkey = $this->table . ($this->context ? '.' . $this->context : '');
147  $this->disabledItems = GeneralUtility::trimExplode(',', $this->backendUser->getTSConfigVal('options.contextMenu.table.' . $TSkey . '.disableItems'), true);
148  }
149 
156  public function addItems(array $items): array
157  {
158  $this->initialize();
159  $items += $this->prepareItems($this->itemsConfiguration);
160  return $items;
161  }
162 
169  protected function prepareItems(array $itemsConfiguration): array
170  {
171  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
172  $items = [];
173  foreach ($itemsConfiguration as $name => $configuration) {
174  $type = !empty($configuration['type']) ? $configuration['type'] : 'item';
175  if ($this->canRender($name, $type)) {
176  $items[$name] = [
177  'type' => $type,
178  'label' => !empty($configuration['label']) ? htmlspecialchars($this->languageService->sL($configuration['label'])) : '',
179  'icon' => !empty($configuration['iconIdentifier']) ? $iconFactory->getIcon($configuration['iconIdentifier'], Icon::SIZE_SMALL)->render() : '',
180  'additionalAttributes' => $this->getAdditionalAttributes($name),
181  'callbackAction' => !empty($configuration['callbackAction']) ? $configuration['callbackAction'] : ''
182  ];
183  if ($type === 'submenu') {
184  $items[$name]['childItems'] = $this->prepareItems($configuration['childItems']);
185  }
186  }
187  }
188  return $items;
189  }
190 
198  protected function getAdditionalAttributes(string $itemName): array
199  {
200  return [];
201  }
202 
210  protected function canRender(string $itemName, string $type): bool
211  {
212  return true;
213  }
214 
220  protected function getIdentifier(): string
221  {
222  return '';
223  }
224 }
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static makeInstance($className,... $constructorArguments)
__construct(string $table, string $identifier, string $context='')
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']