‪TYPO3CMS  9.5
ArrayTreeRenderer.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 
18 
23 {
29  protected ‪$recursionLevel = 0;
30 
38  public function ‪renderNode(\‪TYPO3\CMS\Backend\Tree\TreeRepresentationNode $node, $recursive = true)
39  {
40  $nodeArray = [];
41  $nodeArray[] = $this->‪getNodeArray($node);
42  if ($recursive && $node->hasChildNodes()) {
43  $this->recursionLevel++;
44  $children = $this->‪renderNodeCollection($node->getChildNodes());
45  foreach ($children as $child) {
46  $nodeArray[] = $child;
47  }
48  $this->recursionLevel--;
49  }
50  return $nodeArray;
51  }
52 
59  protected function ‪getNodeArray(\‪TYPO3\CMS\Backend\Tree\TreeRepresentationNode $node)
60  {
61  $overlayIconName = '';
62  if (is_object($node->getIcon())) {
63  $iconName = $node->getIcon()->getIdentifier();
64  if (is_object($node->getIcon()->getOverlayIcon())) {
65  $overlayIconName = $node->getIcon()->getOverlayIcon()->getIdentifier();
66  }
67  } else {
68  $iconName = $node->getIcon();
69  }
70  $nodeArray = [
71  'identifier' => htmlspecialchars($node->getId()),
72  // No need for htmlspecialchars() here as d3 is using 'textContent' property of the HTML DOM node
73  'name' => $node->getLabel(),
74  'icon' => $iconName,
75  'overlayIcon' => $overlayIconName,
76  'depth' => ‪$this->recursionLevel,
77  'hasChildren' => (bool)$node->hasChildNodes(),
78  'selectable' => true,
79  ];
80  if ($node instanceof ‪DatabaseTreeNode) {
81  $nodeArray['checked'] = (bool)$node->getSelected();
82  if (!$node->getSelectable()) {
83  $nodeArray['checked'] = false;
84  $nodeArray['selectable'] = false;
85  }
86  }
87  return $nodeArray;
88  }
89 
97  public function ‪renderTree(\‪TYPO3\CMS\Backend\Tree\AbstractTree $tree, $recursive = true)
98  {
99  $this->recursionLevel = 0;
100  return $this->‪renderNode($tree->getRoot(), $recursive);
101  }
102 
110  public function ‪renderNodeCollection(‪TreeNodeCollection $collection, $recursive = true)
111  {
112  $treeItems = [];
113  foreach ($collection as $node) {
114  $allNodes = $this->‪renderNode($node, $recursive);
115  if ($allNodes[0]) {
116  $treeItems[] = $allNodes[0];
117  }
118  $nodeCount = count($allNodes);
119  if ($nodeCount > 1) {
120  for ($i = 1; $i < $nodeCount; $i++) {
121  $treeItems[] = $allNodes[$i];
122  }
123  }
124  }
125  return $treeItems;
126  }
127 }
‪TYPO3\CMS\Core\Tree\TableConfiguration\ArrayTreeRenderer\renderNode
‪array renderNode(\TYPO3\CMS\Backend\Tree\TreeRepresentationNode $node, $recursive=true)
Definition: ArrayTreeRenderer.php:37
‪TYPO3
‪TYPO3\CMS\Core\Tree\TableConfiguration\DatabaseTreeNode
Definition: DatabaseTreeNode.php:21
‪TYPO3\CMS\Core\Tree\TableConfiguration\ArrayTreeRenderer\renderNodeCollection
‪array renderNodeCollection(TreeNodeCollection $collection, $recursive=true)
Definition: ArrayTreeRenderer.php:109
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection
Definition: TreeNodeCollection.php:21
‪TYPO3\CMS\Core\Tree\TableConfiguration
Definition: AbstractTableConfigurationTreeDataProvider.php:2
‪TYPO3\CMS\Core\Tree\TableConfiguration\ArrayTreeRenderer\renderTree
‪array renderTree(\TYPO3\CMS\Backend\Tree\AbstractTree $tree, $recursive=true)
Definition: ArrayTreeRenderer.php:96
‪TYPO3\CMS\Core\Tree\TableConfiguration\ArrayTreeRenderer\getNodeArray
‪array getNodeArray(\TYPO3\CMS\Backend\Tree\TreeRepresentationNode $node)
Definition: ArrayTreeRenderer.php:58
‪TYPO3\CMS\Core\Tree\TableConfiguration\ArrayTreeRenderer\$recursionLevel
‪int $recursionLevel
Definition: ArrayTreeRenderer.php:28
‪TYPO3\CMS\Backend\Tree\Renderer\AbstractTreeRenderer
Definition: AbstractTreeRenderer.php:21
‪TYPO3\CMS\Core\Tree\TableConfiguration\ArrayTreeRenderer
Definition: ArrayTreeRenderer.php:23