638de8793b75c7b63c77473506f7b9faab6fbef7
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Tree / Pagetree / ExtdirectTreeDataProvider.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tree\Pagetree;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Imaging\Icon;
18 use TYPO3\CMS\Core\Imaging\IconFactory;
19 use TYPO3\CMS\Core\Type\Bitmask\JsConfirmation;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22 /**
23 * Data Provider of the Page Tree
24 */
25 class ExtdirectTreeDataProvider extends \TYPO3\CMS\Backend\Tree\AbstractTree
26 {
27 /**
28 * Data Provider
29 *
30 * @var \TYPO3\CMS\Backend\Tree\Pagetree\DataProvider
31 */
32 protected $dataProvider = null;
33
34 /**
35 * @var IconFactory
36 */
37 protected $iconFactory;
38
39 /**
40 * Constructor
41 */
42 public function __construct()
43 {
44 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
45 }
46
47 /**
48 * Sets the data provider
49 *
50 * @return void
51 */
52 protected function initDataProvider()
53 {
54 /** @var $dataProvider \TYPO3\CMS\Backend\Tree\Pagetree\DataProvider */
55 $dataProvider = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\DataProvider::class);
56 $this->setDataProvider($dataProvider);
57 }
58
59 /**
60 * Returns the root node of the tree
61 *
62 * @return array
63 */
64 public function getRoot()
65 {
66 $this->initDataProvider();
67 $node = $this->dataProvider->getRoot();
68 return $node->toArray();
69 }
70
71 /**
72 * Fetches the next tree level
73 *
74 * @param int $nodeId
75 * @param stdClass $nodeData
76 * @return array
77 */
78 public function getNextTreeLevel($nodeId, $nodeData)
79 {
80 $this->initDataProvider();
81 /** @var $node \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode */
82 $node = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode::class, (array)$nodeData);
83 if ($nodeId === 'root') {
84 $nodeCollection = $this->dataProvider->getTreeMounts();
85 } else {
86 $nodeCollection = $this->dataProvider->getNodes($node, $node->getMountPoint());
87 }
88 return $nodeCollection->toArray();
89 }
90
91 /**
92 * Returns a tree that only contains elements that match the given search string
93 *
94 * @param int $nodeId
95 * @param stdClass $nodeData
96 * @param string $searchFilter
97 * @return array
98 */
99 public function getFilteredTree($nodeId, $nodeData, $searchFilter)
100 {
101 if (strval($searchFilter) === '') {
102 return [];
103 }
104 /** @var $node \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode */
105 $node = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode::class, (array)$nodeData);
106 $this->initDataProvider();
107 if ($nodeId === 'root') {
108 $nodeCollection = $this->dataProvider->getTreeMounts($searchFilter);
109 } else {
110 $nodeCollection = $this->dataProvider->getFilteredNodes($node, $searchFilter, $node->getMountPoint());
111 }
112 return $nodeCollection->toArray();
113 }
114
115 /**
116 * Returns the localized list of doktypes to display
117 *
118 * Note: The list can be filtered by the user typoscript
119 * option "options.pageTree.doktypesToShowInNewPageDragArea".
120 *
121 * @return array
122 */
123 public function getNodeTypes()
124 {
125 $doktypeLabelMap = [];
126 foreach ($GLOBALS['TCA']['pages']['columns']['doktype']['config']['items'] as $doktypeItemConfig) {
127 if ($doktypeItemConfig[1] === '--div--') {
128 continue;
129 }
130 $doktypeLabelMap[$doktypeItemConfig[1]] = $doktypeItemConfig[0];
131 }
132 $doktypes = GeneralUtility::trimExplode(',', $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.doktypesToShowInNewPageDragArea'));
133 $output = [];
134 $allowedDoktypes = GeneralUtility::trimExplode(',', $GLOBALS['BE_USER']->groupData['pagetypes_select'], true);
135 $isAdmin = $GLOBALS['BE_USER']->isAdmin();
136 // Early return if backend user may not create any doktype
137 if (!$isAdmin && empty($allowedDoktypes)) {
138 return $output;
139 }
140 foreach ($doktypes as $doktype) {
141 if (!$isAdmin && !in_array($doktype, $allowedDoktypes)) {
142 continue;
143 }
144 $label = htmlspecialchars($GLOBALS['LANG']->sL($doktypeLabelMap[$doktype]));
145 $icon = $this->iconFactory->getIcon($GLOBALS['TCA']['pages']['ctrl']['typeicon_classes'][$doktype], Icon::SIZE_SMALL)->render();
146 $output[] = [
147 'nodeType' => $doktype,
148 'cls' => 'typo3-pagetree-topPanel-button',
149 'html' => $icon,
150 'title' => $label,
151 'tooltip' => $label
152 ];
153 }
154 return $output;
155 }
156
157 /**
158 * Returns the language labels and configuration options for the pagetree
159 *
160 * @return array
161 */
162 public function loadResources()
163 {
164 $file = 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:';
165 $configuration = [
166 'LLL' => [
167 'copyHint' => htmlspecialchars($GLOBALS['LANG']->sL($file . 'tree.copyHint')),
168 'fakeNodeHint' => htmlspecialchars($GLOBALS['LANG']->sL($file . 'mess.please_wait')),
169 'activeFilterMode' => htmlspecialchars($GLOBALS['LANG']->sL($file . 'tree.activeFilterMode')),
170 'dropToRemove' => htmlspecialchars($GLOBALS['LANG']->sL($file . 'tree.dropToRemove')),
171 'buttonRefresh' => htmlspecialchars($GLOBALS['LANG']->sL($file . 'labels.refresh')),
172 'buttonNewNode' => htmlspecialchars($GLOBALS['LANG']->sL($file . 'tree.buttonNewNode')),
173 'buttonFilter' => htmlspecialchars($GLOBALS['LANG']->sL($file . 'tree.buttonFilter')),
174 'dropZoneElementRemoved' => htmlspecialchars($GLOBALS['LANG']->sL($file . 'tree.dropZoneElementRemoved')),
175 'dropZoneElementRestored' => htmlspecialchars($GLOBALS['LANG']->sL($file . 'tree.dropZoneElementRestored')),
176 'searchTermInfo' => htmlspecialchars($GLOBALS['LANG']->sL($file . 'tree.searchTermInfo')),
177 'temporaryMountPointIndicatorInfo' => htmlspecialchars($GLOBALS['LANG']->sL($file . 'labels.temporaryDBmount')),
178 'deleteDialogTitle' => htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:deleteItem')),
179 'deleteDialogMessage' => htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:deleteWarning')),
180 'recursiveDeleteDialogMessage' => htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:recursiveDeleteWarning'))
181 ],
182 'Configuration' => [
183 'hideFilter' => $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.hideFilter'),
184 'displayDeleteConfirmation' => $GLOBALS['BE_USER']->jsConfirmation(JsConfirmation::DELETE),
185 'canDeleteRecursivly' => $GLOBALS['BE_USER']->uc['recursiveDelete'] == true,
186 'disableIconLinkToContextmenu' => $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.disableIconLinkToContextmenu'),
187 'temporaryMountPoint' => Commands::getMountPointPath()
188 ],
189 'Icons' => [
190 'InputClear' => $this->iconFactory->getIcon('actions-input-clear', Icon::SIZE_SMALL)->render(),
191 'Close' => $this->iconFactory->getIcon('actions-close', Icon::SIZE_SMALL)->render('inline'),
192 'TrashCan' => $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render('inline'),
193 'TrashCanRestore' => $this->iconFactory->getIcon('actions-edit-restore', Icon::SIZE_SMALL)->render('inline'),
194 'Info' => $this->iconFactory->getIcon('actions-document-info', Icon::SIZE_SMALL)->render('inline'),
195 'NewNode' => $this->iconFactory->getIcon('actions-page-new', Icon::SIZE_SMALL)->render(),
196 'Filter' => $this->iconFactory->getIcon('actions-filter', Icon::SIZE_SMALL)->render(),
197 'Refresh' => $this->iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL)->render()
198 ]
199 ];
200 return $configuration;
201 }
202 }