‪TYPO3CMS  ‪main
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 
52  public function ‪canHandle(): bool
53  {
54  return $this->table !== 'sys_file';
55  }
56 
60  public function ‪getPriority(): int
61  {
62  return 50;
63  }
64 
68  public function ‪addItems(array $items): array
69  {
70  $this->‪initDisabledItems();
71  $localItems = $this->‪prepareItems($this->itemsConfiguration);
72  if (isset($items['more']['childItems'])) {
73  $items['more']['childItems'] = $items['more']['childItems'] + $localItems;
74  } else {
75  $items += $localItems;
76  }
77  return $items;
78  }
79 
80  protected function ‪canRender(string $itemName, string $type): bool
81  {
82  if (in_array($itemName, $this->disabledItems, true)) {
83  return false;
84  }
85  $canRender = false;
86  switch ($itemName) {
87  case 'exportT3d':
88  $canRender = $this->backendUser->isExportEnabled();
89  break;
90  case 'importT3d':
91  $canRender = $this->table === 'pages' && $this->backendUser->isImportEnabled();
92  break;
93  }
94  return $canRender;
95  }
96 
100  protected function ‪getAdditionalAttributes(string $itemName): array
101  {
102  $attributes = [
103  'data-callback-module' => '@typo3/impexp/context-menu-actions',
104  ];
105 
106  // Add action url for items
107  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
108  switch ($itemName) {
109  case 'exportT3d':
110  $attributes['data-action-url'] = (string)$uriBuilder->buildUriFromRoute('tx_impexp_export');
111  break;
112  case 'importT3d':
113  $attributes['data-action-url'] = (string)$uriBuilder->buildUriFromRoute('tx_impexp_import');
114  break;
115  }
116 
117  return $attributes;
118  }
119 }
‪TYPO3\CMS\Impexp\ContextMenu\ItemProvider\canRender
‪canRender(string $itemName, string $type)
Definition: ItemProvider.php:79
‪TYPO3\CMS\Impexp\ContextMenu\ItemProvider\getAdditionalAttributes
‪getAdditionalAttributes(string $itemName)
Definition: ItemProvider.php:99
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider\prepareItems
‪prepareItems(array $itemsConfiguration)
Definition: AbstractProvider.php:156
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider
Definition: AbstractProvider.php:31
‪TYPO3\CMS\Impexp\ContextMenu\ItemProvider\getPriority
‪getPriority()
Definition: ItemProvider.php:59
‪TYPO3\CMS\Impexp\ContextMenu
Definition: ItemProvider.php:18
‪TYPO3\CMS\Impexp\ContextMenu\ItemProvider\addItems
‪addItems(array $items)
Definition: ItemProvider.php:67
‪TYPO3\CMS\Impexp\ContextMenu\ItemProvider
Definition: ItemProvider.php:30
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:44
‪TYPO3\CMS\Impexp\ContextMenu\ItemProvider\canHandle
‪canHandle()
Definition: ItemProvider.php:51
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider\initDisabledItems
‪initDisabledItems()
Definition: AbstractProvider.php:133
‪TYPO3\CMS\Impexp\ContextMenu\ItemProvider\$itemsConfiguration
‪array $itemsConfiguration
Definition: ItemProvider.php:33