[BUGFIX] Fix several typos in php comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / impexp / Classes / ContextMenu / ItemProvider.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Impexp\ContextMenu;
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
18 use TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider;
19
20 /**
21 * Context menu item provider adding export and import items
22 * @internal this is an internal TYPO3 hook implementation and solely used for EXT:impexp and not part of TYPO3's Core API.
23 */
24 class ItemProvider extends AbstractProvider
25 {
26 /**
27 * @var array
28 */
29 protected $itemsConfiguration = [
30 'exportT3d' => [
31 'type' => 'item',
32 'label' => 'LLL:EXT:impexp/Resources/Private/Language/locallang.xlf:export',
33 'iconIdentifier' => 'actions-document-export-t3d',
34 'callbackAction' => 'exportT3d'
35 ],
36 'importT3d' => [
37 'type' => 'item',
38 'label' => 'LLL:EXT:impexp/Resources/Private/Language/locallang.xlf:import',
39 'iconIdentifier' => 'actions-document-import-t3d',
40 'callbackAction' => 'importT3d',
41 ]
42 ];
43
44 /**
45 * Export item is added for all database records except files
46 *
47 * @return bool
48 */
49 public function canHandle(): bool
50 {
51 return !in_array($this->table, ['sys_file', 'sys_filemounts', 'sys_file_storage'], true)
52 && strpos($this->table, '-drag') === false;
53 }
54
55 /**
56 * This needs to be lower than priority of the RecordProvider
57 *
58 * @return int
59 */
60 public function getPriority(): int
61 {
62 return 50;
63 }
64
65 /**
66 * Adds import/export items to the "submenu" if available
67 *
68 * @param array $items
69 * @return array
70 */
71 public function addItems(array $items): array
72 {
73 $this->initDisabledItems();
74 $localItems = $this->prepareItems($this->itemsConfiguration);
75 if (isset($items['more']['childItems'])) {
76 $items['more']['childItems'] = $items['more']['childItems'] + $localItems;
77 } else {
78 $items += $localItems;
79 }
80 return $items;
81 }
82
83 /**
84 * @param string $itemName
85 * @param string $type
86 * @return bool
87 */
88 protected function canRender(string $itemName, string $type): bool
89 {
90 if (in_array($itemName, $this->disabledItems, true)) {
91 return false;
92 }
93 $canRender = false;
94 switch ($itemName) {
95 case 'exportT3d':
96 $canRender = true;
97 break;
98 case 'importT3d':
99 $canRender = $this->table === 'pages' && $this->isImportEnabled();
100 break;
101 }
102 return $canRender;
103 }
104
105 /**
106 * Registers custom JS module with item onclick behaviour
107 *
108 * @param string $itemName
109 * @return array
110 */
111 protected function getAdditionalAttributes(string $itemName): array
112 {
113 return ['data-callback-module' => 'TYPO3/CMS/Impexp/ContextMenuActions'];
114 }
115
116 /**
117 * Check if import functionality is available for current user
118 */
119 protected function isImportEnabled(): bool
120 {
121 return $this->backendUser->isAdmin()
122 || !$this->backendUser->isAdmin() && (bool)($this->backendUser->getTSConfig()['options.']['impexp.']['enableImportForNonAdminUser'] ?? false);
123 }
124 }