[BUGFIX] Show labels of additional doktypes in new page drag area
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Tree / Pagetree / ExtdirectTreeDataProvider.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tree\Pagetree;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 TYPO3 Tree Team <http://forge.typo3.org/projects/typo3v4-extjstrees>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Backend\Tree\Pagetree\Commands;
31 use TYPO3\CMS\Backend\Utility\IconUtility;
32 use TYPO3\CMS\Core\Utility\GeneralUtility;
33
34 /**
35 * Data Provider of the Page Tree
36 *
37 * @author Stefan Galinski <stefan.galinski@gmail.com>
38 */
39 class ExtdirectTreeDataProvider extends \TYPO3\CMS\Backend\Tree\AbstractExtJsTree {
40
41 /**
42 * Data Provider
43 *
44 * @var \TYPO3\CMS\Backend\Tree\Pagetree\DataProvider
45 */
46 protected $dataProvider = NULL;
47
48 /**
49 * Sets the data provider
50 *
51 * @return void
52 */
53 protected function initDataProvider() {
54 /** @var $dataProvider \TYPO3\CMS\Backend\Tree\Pagetree\DataProvider */
55 $dataProvider = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\DataProvider');
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 $this->initDataProvider();
66 $node = $this->dataProvider->getRoot();
67 return $node->toArray();
68 }
69
70 /**
71 * Fetches the next tree level
72 *
73 * @param integer $nodeId
74 * @param stdClass $nodeData
75 * @return array
76 */
77 public function getNextTreeLevel($nodeId, $nodeData) {
78 $this->initDataProvider();
79 /** @var $node \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode */
80 $node = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNode', (array) $nodeData);
81 if ($nodeId === 'root') {
82 $nodeCollection = $this->dataProvider->getTreeMounts();
83 } else {
84 $nodeCollection = $this->dataProvider->getNodes($node, $node->getMountPoint());
85 }
86 return $nodeCollection->toArray();
87 }
88
89 /**
90 * Returns a tree that only contains elements that match the given search string
91 *
92 * @param integer $nodeId
93 * @param stdClass $nodeData
94 * @param string $searchFilter
95 * @return array
96 */
97 public function getFilteredTree($nodeId, $nodeData, $searchFilter) {
98 if (strval($searchFilter) === '') {
99 return array();
100 }
101 /** @var $node \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode */
102 $node = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNode', (array) $nodeData);
103 $this->initDataProvider();
104 if ($nodeId === 'root') {
105 $nodeCollection = $this->dataProvider->getTreeMounts($searchFilter);
106 } else {
107 $nodeCollection = $this->dataProvider->getFilteredNodes($node, $searchFilter, $node->getMountPoint());
108 }
109 return $nodeCollection->toArray();
110 }
111
112 /**
113 * Returns the localized list of doktypes to display
114 *
115 * Note: The list can be filtered by the user typoscript
116 * option "options.pageTree.doktypesToShowInNewPageDragArea".
117 *
118 * @return array
119 */
120 public function getNodeTypes() {
121 $doktypeLabelMap = array();
122 foreach ($GLOBALS['TCA']['pages']['columns']['doktype']['config']['items'] as $doktypeItemConfig) {
123 if ($doktypeItemConfig[1] === '--div--') {
124 continue;
125 }
126 $doktypeLabelMap[$doktypeItemConfig[1]] = $doktypeItemConfig[0];
127 }
128 $doktypes = GeneralUtility::trimExplode(',', $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.doktypesToShowInNewPageDragArea'));
129 $output = array();
130 $allowedDoktypes = GeneralUtility::trimExplode(',', $GLOBALS['BE_USER']->groupData['pagetypes_select']);
131 $isAdmin = $GLOBALS['BE_USER']->isAdmin();
132 foreach ($doktypes as $doktype) {
133 if (!$isAdmin && !in_array($doktype, $allowedDoktypes)) {
134 continue;
135 }
136 $label = $GLOBALS['LANG']->sL($doktypeLabelMap[$doktype], TRUE);
137 $spriteIcon = IconUtility::getSpriteIconClasses($GLOBALS['TCA']['pages']['ctrl']['typeicon_classes'][$doktype]);
138 $output[] = array(
139 'nodeType' => $doktype,
140 'cls' => 'typo3-pagetree-topPanel-button',
141 'iconCls' => $spriteIcon,
142 'title' => $label,
143 'tooltip' => $label
144 );
145 }
146 return $output;
147 }
148
149 /**
150 * Returns
151 *
152 * @return array
153 */
154 public function getIndicators() {
155 /** @var $indicatorProvider \TYPO3\CMS\Backend\Tree\Pagetree\Indicator */
156 $indicatorProvider = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\Indicator');
157 $indicatorHtmlArr = $indicatorProvider->getAllIndicators();
158 $indicator = array(
159 'html' => implode(' ', $indicatorHtmlArr),
160 '_COUNT' => count($indicatorHtmlArr)
161 );
162 return $indicator;
163 }
164
165 /**
166 * Returns the language labels, sprites and configuration options for the pagetree
167 *
168 * @return void
169 */
170 public function loadResources() {
171 $file = 'LLL:EXT:lang/locallang_core.xlf:';
172 $indicators = $this->getIndicators();
173 $configuration = array(
174 'LLL' => array(
175 'copyHint' => $GLOBALS['LANG']->sL($file . 'tree.copyHint', TRUE),
176 'fakeNodeHint' => $GLOBALS['LANG']->sL($file . 'mess.please_wait', TRUE),
177 'activeFilterMode' => $GLOBALS['LANG']->sL($file . 'tree.activeFilterMode', TRUE),
178 'dropToRemove' => $GLOBALS['LANG']->sL($file . 'tree.dropToRemove', TRUE),
179 'buttonRefresh' => $GLOBALS['LANG']->sL($file . 'labels.refresh', TRUE),
180 'buttonNewNode' => $GLOBALS['LANG']->sL($file . 'tree.buttonNewNode', TRUE),
181 'buttonFilter' => $GLOBALS['LANG']->sL($file . 'tree.buttonFilter', TRUE),
182 'dropZoneElementRemoved' => $GLOBALS['LANG']->sL($file . 'tree.dropZoneElementRemoved', TRUE),
183 'dropZoneElementRestored' => $GLOBALS['LANG']->sL($file . 'tree.dropZoneElementRestored', TRUE),
184 'searchTermInfo' => $GLOBALS['LANG']->sL($file . 'tree.searchTermInfo', TRUE),
185 'temporaryMountPointIndicatorInfo' => $GLOBALS['LANG']->sl($file . 'labels.temporaryDBmount', TRUE),
186 'deleteDialogTitle' => $GLOBALS['LANG']->sL('LLL:EXT:cms/layout/locallang.xlf:deleteItem', TRUE),
187 'deleteDialogMessage' => $GLOBALS['LANG']->sL('LLL:EXT:cms/layout/locallang.xlf:deleteWarning', TRUE),
188 'recursiveDeleteDialogMessage' => $GLOBALS['LANG']->sL('LLL:EXT:cms/layout/locallang.xlf:recursiveDeleteWarning', TRUE)
189 ),
190 'Configuration' => array(
191 'hideFilter' => $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.hideFilter'),
192 'displayDeleteConfirmation' => $GLOBALS['BE_USER']->jsConfirmation(4),
193 'canDeleteRecursivly' => $GLOBALS['BE_USER']->uc['recursiveDelete'] == TRUE,
194 'disableIconLinkToContextmenu' => $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.disableIconLinkToContextmenu'),
195 'indicator' => $indicators['html'],
196 'temporaryMountPoint' => Commands::getMountPointPath()
197 ),
198 'Sprites' => array(
199 'Filter' => IconUtility::getSpriteIconClasses('actions-system-tree-search-open'),
200 'NewNode' => IconUtility::getSpriteIconClasses('actions-page-new'),
201 'Refresh' => IconUtility::getSpriteIconClasses('actions-system-refresh'),
202 'InputClear' => IconUtility::getSpriteIconClasses('actions-input-clear'),
203 'TrashCan' => IconUtility::getSpriteIconClasses('actions-edit-delete'),
204 'TrashCanRestore' => IconUtility::getSpriteIconClasses('actions-edit-restore'),
205 'Info' => IconUtility::getSpriteIconClasses('actions-document-info')
206 )
207 );
208 return $configuration;
209 }
210
211 }