[!!!][FEATURE] Replace ExtJS page tree
[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\IconFactory;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * Data Provider of the Page Tree
22 */
23 class ExtdirectTreeDataProvider extends \TYPO3\CMS\Backend\Tree\AbstractTree
24 {
25 /**
26 * Data Provider
27 *
28 * @var \TYPO3\CMS\Backend\Tree\Pagetree\DataProvider
29 */
30 protected $dataProvider = null;
31
32 /**
33 * @var IconFactory
34 */
35 protected $iconFactory;
36
37 /**
38 * Constructor
39 */
40 public function __construct()
41 {
42 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
43 }
44
45 /**
46 * Sets the data provider
47 */
48 protected function initDataProvider()
49 {
50 /** @var $dataProvider \TYPO3\CMS\Backend\Tree\Pagetree\DataProvider */
51 $dataProvider = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\DataProvider::class);
52 $this->setDataProvider($dataProvider);
53 }
54
55 /**
56 * Returns the root node of the tree
57 *
58 * @return array
59 */
60 public function getRoot()
61 {
62 $this->initDataProvider();
63 $node = $this->dataProvider->getRoot();
64 return $node->toArray();
65 }
66
67 /**
68 * Fetches the next tree level
69 *
70 * @param int $nodeId
71 * @param \stdClass $nodeData
72 * @return array
73 */
74 public function getNextTreeLevel($nodeId, $nodeData)
75 {
76 $this->initDataProvider();
77 /** @var $node \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode */
78 $node = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode::class, (array)$nodeData);
79 if ($nodeId === 'root') {
80 $nodeCollection = $this->dataProvider->getTreeMounts();
81 } else {
82 $nodeCollection = $this->dataProvider->getNodes($node, $node->getMountPoint());
83 }
84 return $nodeCollection->toArray();
85 }
86
87 /**
88 * Returns a tree that only contains elements that match the given search string
89 *
90 * @param int $nodeId
91 * @param \stdClass $nodeData
92 * @param string $searchFilter
93 * @return array
94 */
95 public function getFilteredTree($nodeId, $nodeData, $searchFilter)
96 {
97 if (strval($searchFilter) === '') {
98 return [];
99 }
100 /** @var $node \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode */
101 $node = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode::class, (array)$nodeData);
102 $this->initDataProvider();
103 if ($nodeId === 'root') {
104 $nodeCollection = $this->dataProvider->getTreeMounts($searchFilter);
105 } else {
106 $nodeCollection = $this->dataProvider->getFilteredNodes($node, $searchFilter, $node->getMountPoint());
107 }
108 return $nodeCollection->toArray();
109 }
110 }