TYPO3 CMS  TYPO3_8-7
ExtdirectTreeDataProvider.php
Go to the documentation of this file.
1 <?php
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 
21 
26 {
32  protected $dataProvider = null;
33 
37  protected $iconFactory;
38 
42  public function __construct()
43  {
44  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
45  }
46 
50  protected function initDataProvider()
51  {
53  $dataProvider = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\DataProvider::class);
55  }
56 
62  public function getRoot()
63  {
64  $this->initDataProvider();
65  $node = $this->dataProvider->getRoot();
66  return $node->toArray();
67  }
68 
76  public function getNextTreeLevel($nodeId, $nodeData)
77  {
78  $this->initDataProvider();
80  $node = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode::class, (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 
97  public function getFilteredTree($nodeId, $nodeData, $searchFilter)
98  {
99  if (strval($searchFilter) === '') {
100  return [];
101  }
103  $node = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode::class, (array)$nodeData);
104  $this->initDataProvider();
105  if ($nodeId === 'root') {
106  $nodeCollection = $this->dataProvider->getTreeMounts($searchFilter);
107  } else {
108  $nodeCollection = $this->dataProvider->getFilteredNodes($node, $searchFilter, $node->getMountPoint());
109  }
110  return $nodeCollection->toArray();
111  }
112 
121  public function getNodeTypes()
122  {
123  $doktypeLabelMap = [];
124  foreach ($GLOBALS['TCA']['pages']['columns']['doktype']['config']['items'] as $doktypeItemConfig) {
125  if ($doktypeItemConfig[1] === '--div--') {
126  continue;
127  }
128  $doktypeLabelMap[$doktypeItemConfig[1]] = $doktypeItemConfig[0];
129  }
130  $doktypes = GeneralUtility::trimExplode(',', $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.doktypesToShowInNewPageDragArea'));
131  $output = [];
132  $allowedDoktypes = GeneralUtility::trimExplode(',', $GLOBALS['BE_USER']->groupData['pagetypes_select'], true);
133  $isAdmin = $GLOBALS['BE_USER']->isAdmin();
134  // Early return if backend user may not create any doktype
135  if (!$isAdmin && empty($allowedDoktypes)) {
136  return $output;
137  }
138  foreach ($doktypes as $doktype) {
139  if (!$isAdmin && !in_array($doktype, $allowedDoktypes)) {
140  continue;
141  }
142  $label = htmlspecialchars($GLOBALS['LANG']->sL($doktypeLabelMap[$doktype]));
143  $icon = $this->iconFactory->getIcon($GLOBALS['TCA']['pages']['ctrl']['typeicon_classes'][$doktype], Icon::SIZE_SMALL)->render();
144  $output[] = [
145  'nodeType' => $doktype,
146  'cls' => 'typo3-pagetree-topPanel-button',
147  'html' => $icon,
148  'title' => $label,
149  'tooltip' => $label
150  ];
151  }
152  return $output;
153  }
154 
160  public function loadResources()
161  {
162  $file = 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:';
163  $configuration = [
164  'LLL' => [
165  'copyHint' => htmlspecialchars($GLOBALS['LANG']->sL($file . 'tree.copyHint')),
166  'fakeNodeHint' => htmlspecialchars($GLOBALS['LANG']->sL($file . 'mess.please_wait')),
167  'activeFilterMode' => htmlspecialchars($GLOBALS['LANG']->sL($file . 'tree.activeFilterMode')),
168  'dropToRemove' => htmlspecialchars($GLOBALS['LANG']->sL($file . 'tree.dropToRemove')),
169  'buttonRefresh' => htmlspecialchars($GLOBALS['LANG']->sL($file . 'labels.refresh')),
170  'buttonNewNode' => htmlspecialchars($GLOBALS['LANG']->sL($file . 'tree.buttonNewNode')),
171  'buttonFilter' => htmlspecialchars($GLOBALS['LANG']->sL($file . 'tree.buttonFilter')),
172  'dropZoneElementRemoved' => htmlspecialchars($GLOBALS['LANG']->sL($file . 'tree.dropZoneElementRemoved')),
173  'dropZoneElementRestored' => htmlspecialchars($GLOBALS['LANG']->sL($file . 'tree.dropZoneElementRestored')),
174  'searchTermInfo' => htmlspecialchars($GLOBALS['LANG']->sL($file . 'tree.searchTermInfo')),
175  'temporaryMountPointIndicatorInfo' => htmlspecialchars($GLOBALS['LANG']->sL($file . 'labels.temporaryDBmount')),
176  'deleteDialogTitle' => htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:deleteItem')),
177  'deleteDialogMessage' => htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:deleteWarning')),
178  'recursiveDeleteDialogMessage' => htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:recursiveDeleteWarning'))
179  ],
180  'Configuration' => [
181  'hideFilter' => $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.hideFilter'),
182  'displayDeleteConfirmation' => $GLOBALS['BE_USER']->jsConfirmation(JsConfirmation::DELETE),
183  'canDeleteRecursivly' => $GLOBALS['BE_USER']->uc['recursiveDelete'] == true,
184  'disableIconLinkToContextmenu' => $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.disableIconLinkToContextmenu'),
185  'temporaryMountPoint' => Commands::getMountPointPath()
186  ],
187  'Icons' => [
188  'InputClear' => $this->iconFactory->getIcon('actions-input-clear', Icon::SIZE_SMALL)->render(),
189  'Close' => $this->iconFactory->getIcon('actions-close', Icon::SIZE_SMALL)->render('inline'),
190  'TrashCan' => $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render('inline'),
191  'TrashCanRestore' => $this->iconFactory->getIcon('actions-edit-restore', Icon::SIZE_SMALL)->render('inline'),
192  'Info' => $this->iconFactory->getIcon('actions-document-info', Icon::SIZE_SMALL)->render('inline'),
193  'NewNode' => $this->iconFactory->getIcon('actions-page-new', Icon::SIZE_SMALL)->render(),
194  'Filter' => $this->iconFactory->getIcon('actions-filter', Icon::SIZE_SMALL)->render(),
195  'Refresh' => $this->iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL)->render()
196  ]
197  ];
198  return $configuration;
199  }
200 }
setDataProvider(\TYPO3\CMS\Backend\Tree\AbstractTreeDataProvider $dataProvider)
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']