TYPO3 CMS  TYPO3_8-7
UnorderedListTreeRenderer.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 {
27  protected $recursionLevel = 0;
28 
36  public function renderNode(\TYPO3\CMS\Backend\Tree\TreeRepresentationNode $node, $recursive = true)
37  {
38  $code = '<li><span class="' . htmlspecialchars($node->getIcon()) . '">&nbsp;</span>' . htmlspecialchars($node->getLabel());
39  if ($recursive && $node->getChildNodes() !== null) {
40  $this->recursionLevel++;
41  $code .= $this->renderNodeCollection($node->getChildNodes());
42  $this->recursionLevel--;
43  }
44  $code .= '</li>';
45  return $code;
46  }
47 
55  public function renderTree(\TYPO3\CMS\Backend\Tree\AbstractTree $tree, $recursive = true)
56  {
57  $this->recursionLevel = 0;
58  $code = '<ul class="level' . $this->recursionLevel . '" style="margin-left:10px">';
59  $code .= $this->renderNode($tree->getRoot(), $recursive);
60  $code .= '</ul>';
61  return $code;
62  }
63 
71  public function renderNodeCollection(\TYPO3\CMS\Backend\Tree\TreeNodeCollection $collection, $recursive = true)
72  {
73  $code = '<ul class="level' . $this->recursionLevel . '" style="margin-left:10px">';
74  foreach ($collection as $node) {
75  $code .= $this->renderNode($node, $recursive);
76  }
77  $code .= '</ul>';
78  return $code;
79  }
80 }
renderNode(\TYPO3\CMS\Backend\Tree\TreeRepresentationNode $node, $recursive=true)
renderNodeCollection(\TYPO3\CMS\Backend\Tree\TreeNodeCollection $collection, $recursive=true)
renderTree(\TYPO3\CMS\Backend\Tree\AbstractTree $tree, $recursive=true)