‪TYPO3CMS  11.5
ItemProvider.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 
30 {
34  protected ‪$itemsConfiguration = [
35  'exportT3d' => [
36  'type' => 'item',
37  'label' => 'LLL:EXT:impexp/Resources/Private/Language/locallang.xlf:export',
38  'iconIdentifier' => 'actions-document-export-t3d',
39  'callbackAction' => 'exportT3d',
40  ],
41  'importT3d' => [
42  'type' => 'item',
43  'label' => 'LLL:EXT:impexp/Resources/Private/Language/locallang.xlf:import',
44  'iconIdentifier' => 'actions-document-import-t3d',
45  'callbackAction' => 'importT3d',
46  ],
47  ];
48 
54  public function ‪canHandle(): bool
55  {
56  return $this->table !== 'sys_file';
57  }
58 
64  public function ‪getPriority(): int
65  {
66  return 50;
67  }
68 
75  public function ‪addItems(array $items): array
76  {
77  $this->‪initDisabledItems();
78  $localItems = $this->‪prepareItems($this->itemsConfiguration);
79  if (isset($items['more']['childItems'])) {
80  $items['more']['childItems'] = $items['more']['childItems'] + $localItems;
81  } else {
82  $items += $localItems;
83  }
84  return $items;
85  }
86 
92  protected function ‪canRender(string $itemName, string $type): bool
93  {
94  if (in_array($itemName, $this->disabledItems, true)) {
95  return false;
96  }
97  $canRender = false;
98  switch ($itemName) {
99  case 'exportT3d':
100  $canRender = $this->backendUser->isExportEnabled();
101  break;
102  case 'importT3d':
103  $canRender = $this->table === 'pages' && $this->backendUser->isImportEnabled();
104  break;
105  }
106  return $canRender;
107  }
108 
115  protected function ‪getAdditionalAttributes(string $itemName): array
116  {
117  $attributes = [
118  'data-callback-module' => 'TYPO3/CMS/Impexp/ContextMenuActions',
119  ];
120 
121  // Add action url for items
122  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
123  switch ($itemName) {
124  case 'exportT3d':
125  $attributes['data-action-url'] = htmlspecialchars((string)$uriBuilder->buildUriFromRoute('tx_impexp_export'));
126  break;
127  case 'importT3d':
128  $attributes['data-action-url'] = htmlspecialchars((string)$uriBuilder->buildUriFromRoute('tx_impexp_import'));
129  break;
130  }
131 
132  return $attributes;
133  }
134 }
‪TYPO3\CMS\Impexp\ContextMenu\ItemProvider\getAdditionalAttributes
‪array getAdditionalAttributes(string $itemName)
Definition: ItemProvider.php:114
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider\prepareItems
‪array prepareItems(array $itemsConfiguration)
Definition: AbstractProvider.php:170
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider
Definition: AbstractProvider.php:31
‪TYPO3\CMS\Impexp\ContextMenu\ItemProvider\canRender
‪bool canRender(string $itemName, string $type)
Definition: ItemProvider.php:91
‪TYPO3\CMS\Impexp\ContextMenu
Definition: ItemProvider.php:18
‪TYPO3\CMS\Impexp\ContextMenu\ItemProvider
Definition: ItemProvider.php:30
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:40
‪TYPO3\CMS\Impexp\ContextMenu\ItemProvider\canHandle
‪bool canHandle()
Definition: ItemProvider.php:53
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Impexp\ContextMenu\ItemProvider\addItems
‪array addItems(array $items)
Definition: ItemProvider.php:74
‪TYPO3\CMS\Impexp\ContextMenu\ItemProvider\getPriority
‪int getPriority()
Definition: ItemProvider.php:63
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider\initDisabledItems
‪initDisabledItems()
Definition: AbstractProvider.php:141
‪TYPO3\CMS\Impexp\ContextMenu\ItemProvider\$itemsConfiguration
‪array $itemsConfiguration
Definition: ItemProvider.php:33