‪TYPO3CMS  10.4
ArrayTreeRenderer.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
22 
27 {
33  protected ‪$recursionLevel = 0;
34 
42  public function ‪renderNode(‪TreeRepresentationNode $node, $recursive = true)
43  {
44  $nodeArray = [];
45  $nodeArray[] = $this->‪getNodeArray($node);
46  if ($recursive && $node->‪hasChildNodes()) {
47  $this->recursionLevel++;
48  $children = $this->‪renderNodeCollection($node->‪getChildNodes());
49  foreach ($children as $child) {
50  $nodeArray[] = $child;
51  }
52  $this->recursionLevel--;
53  }
54  return $nodeArray;
55  }
56 
63  protected function ‪getNodeArray(‪TreeRepresentationNode $node)
64  {
65  $overlayIconName = '';
66  if (is_object($node->‪getIcon())) {
67  $iconName = $node->‪getIcon()->‪getIdentifier();
68  if (is_object($node->‪getIcon()->‪getOverlayIcon())) {
69  $overlayIconName = $node->‪getIcon()->‪getOverlayIcon()->‪getIdentifier();
70  }
71  } else {
72  $iconName = $node->‪getIcon();
73  }
74  $nodeArray = [
75  'identifier' => htmlspecialchars($node->‪getId()),
76  // No need for htmlspecialchars() here as d3 is using 'textContent' property of the HTML DOM node
77  'name' => $node->‪getLabel(),
78  'icon' => $iconName,
79  'overlayIcon' => $overlayIconName,
80  'depth' => ‪$this->recursionLevel,
81  'hasChildren' => (bool)$node->‪hasChildNodes(),
82  'selectable' => true,
83  ];
84  if ($node instanceof ‪DatabaseTreeNode) {
85  $nodeArray['checked'] = (bool)$node->getSelected();
86  if (!$node->getSelectable()) {
87  $nodeArray['checked'] = false;
88  $nodeArray['selectable'] = false;
89  }
90  }
91  return $nodeArray;
92  }
93 
101  public function ‪renderTree(‪AbstractTree $tree, $recursive = true)
102  {
103  $this->recursionLevel = 0;
104  return $this->‪renderNode($tree->‪getRoot(), $recursive);
105  }
106 
114  public function ‪renderNodeCollection(‪TreeNodeCollection $collection, $recursive = true)
115  {
116  $treeItems = [];
117  foreach ($collection as $node) {
118  $allNodes = $this->‪renderNode($node, $recursive);
119  if ($allNodes[0]) {
120  $treeItems[] = $allNodes[0];
121  }
122  $nodeCount = count($allNodes);
123  if ($nodeCount > 1) {
124  for ($i = 1; $i < $nodeCount; $i++) {
125  $treeItems[] = $allNodes[$i];
126  }
127  }
128  }
129  return $treeItems;
130  }
131 }
‪TYPO3\CMS\Backend\Tree\TreeRepresentationNode\getLabel
‪string getLabel()
Definition: TreeRepresentationNode.php:98
‪TYPO3\CMS\Backend\Tree\TreeRepresentationNode
Definition: TreeRepresentationNode.php:24
‪TYPO3\CMS\Core\Tree\TableConfiguration\DatabaseTreeNode
Definition: DatabaseTreeNode.php:24
‪TYPO3\CMS\Core\Tree\TableConfiguration\ArrayTreeRenderer\renderNodeCollection
‪array renderNodeCollection(TreeNodeCollection $collection, $recursive=true)
Definition: ArrayTreeRenderer.php:113
‪TYPO3\CMS\Backend\Tree\TreeNode\hasChildNodes
‪bool hasChildNodes()
Definition: TreeNode.php:95
‪TYPO3\CMS\Backend\Tree\AbstractTree\getRoot
‪TYPO3 CMS Backend Tree TreeNode getRoot()
‪TYPO3\CMS\Core\Imaging\Icon\getIdentifier
‪string getIdentifier()
Definition: Icon.php:135
‪TYPO3\CMS\Backend\Tree\TreeNodeCollection
Definition: TreeNodeCollection.php:25
‪TYPO3\CMS\Core\Imaging\Icon\getOverlayIcon
‪Icon getOverlayIcon()
Definition: Icon.php:151
‪TYPO3\CMS\Core\Tree\TableConfiguration
Definition: AbstractTableConfigurationTreeDataProvider.php:16
‪TYPO3\CMS\Core\Tree\TableConfiguration\ArrayTreeRenderer\$recursionLevel
‪int $recursionLevel
Definition: ArrayTreeRenderer.php:32
‪TYPO3\CMS\Core\Tree\TableConfiguration\ArrayTreeRenderer\renderNode
‪array renderNode(TreeRepresentationNode $node, $recursive=true)
Definition: ArrayTreeRenderer.php:41
‪TYPO3\CMS\Core\Tree\TableConfiguration\ArrayTreeRenderer\getNodeArray
‪array getNodeArray(TreeRepresentationNode $node)
Definition: ArrayTreeRenderer.php:62
‪TYPO3\CMS\Core\Tree\TableConfiguration\ArrayTreeRenderer\renderTree
‪array renderTree(AbstractTree $tree, $recursive=true)
Definition: ArrayTreeRenderer.php:100
‪TYPO3\CMS\Backend\Tree\Renderer\AbstractTreeRenderer
Definition: AbstractTreeRenderer.php:26
‪TYPO3\CMS\Backend\Tree\TreeRepresentationNode\getIcon
‪string Icon getIcon()
Definition: TreeRepresentationNode.php:82
‪TYPO3\CMS\Backend\Tree\AbstractTree
Definition: AbstractTree.php:24
‪TYPO3\CMS\Core\Tree\TableConfiguration\ArrayTreeRenderer
Definition: ArrayTreeRenderer.php:27
‪TYPO3\CMS\Backend\Tree\TreeNode\getId
‪string getId()
Definition: TreeNode.php:118
‪TYPO3\CMS\Backend\Tree\TreeNode\getChildNodes
‪TYPO3 CMS Backend Tree TreeNodeCollection getChildNodes()
Definition: TreeNode.php:85