[TASK] Add more fixers for php-cs-fixer
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Tree / Renderer / ExtJsJsonTreeRenderer.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tree\Renderer;
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 use TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider;
17
18 /**
19 * Renderer for unordered lists
20 */
21 class ExtJsJsonTreeRenderer extends \TYPO3\CMS\Backend\Tree\Renderer\AbstractTreeRenderer
22 {
23 /**
24 * recursion level
25 *
26 * @var int
27 */
28 protected $recursionLevel = 0;
29
30 /**
31 * Renders a node recursive or just a single instance
32 *
33 * @param \TYPO3\CMS\Backend\Tree\TreeRepresentationNode $node
34 * @param bool $recursive
35 * @return array
36 */
37 public function renderNode(\TYPO3\CMS\Backend\Tree\TreeRepresentationNode $node, $recursive = true)
38 {
39 $nodeArray = $this->getNodeArray($node);
40 if ($recursive && $node->hasChildNodes()) {
41 $this->recursionLevel++;
42 $children = $this->renderNodeCollection($node->getChildNodes());
43 $nodeArray['children'] = $children;
44 $this->recursionLevel--;
45 }
46 return $nodeArray;
47 }
48
49 /**
50 * Get node array
51 *
52 * @param \TYPO3\CMS\Backend\Tree\TreeRepresentationNode $node
53 * @return array
54 */
55 protected function getNodeArray(\TYPO3\CMS\Backend\Tree\TreeRepresentationNode $node)
56 {
57 $overlayIconMarkup = '';
58 if (is_object($node->getIcon())) {
59 $iconMarkup = $node->getIcon()->getMarkup(SvgIconProvider::MARKUP_IDENTIFIER_INLINE);
60 if (is_object($node->getIcon()->getOverlayIcon())) {
61 $overlayIcon = $node->getIcon()->getOverlayIcon()->getMarkup(SvgIconProvider::MARKUP_IDENTIFIER_INLINE);
62 }
63 } else {
64 $iconMarkup = $node->getIcon();
65 }
66 $nodeArray = [
67 'iconTag' => $iconMarkup,
68 'text' => htmlspecialchars($node->getLabel()),
69 'leaf' => !$node->hasChildNodes(),
70 'id' => htmlspecialchars($node->getId()),
71 'uid' => htmlspecialchars($node->getId()),
72
73 //svgtree
74 'icon' => $iconMarkup,
75 'overlayIcon' => $overlayIconMarkup,
76 'identifier' => htmlspecialchars($node->getId()),
77 //no need for htmlspecialhars here as d3 is using 'textContent' property of the HTML DOM node
78 'name' => $node->getLabel(),
79 ];
80
81 return $nodeArray;
82 }
83
84 /**
85 * Renders a node collection recursive or just a single instance
86 *
87 * @param \TYPO3\CMS\Backend\Tree\TreeNodeCollection $node
88 * @param bool $recursive
89 * @return string
90 */
91 public function renderTree(\TYPO3\CMS\Backend\Tree\AbstractTree $tree, $recursive = true)
92 {
93 $this->recursionLevel = 0;
94 $children = $this->renderNode($tree->getRoot(), $recursive);
95 return json_encode($children);
96 }
97
98 /**
99 * Renders an tree recursive or just a single instance
100 *
101 * @param \TYPO3\CMS\Backend\Tree\AbstractTree $node
102 * @param bool $recursive
103 * @return array
104 */
105 public function renderNodeCollection(\TYPO3\CMS\Backend\Tree\TreeNodeCollection $collection, $recursive = true)
106 {
107 foreach ($collection as $node) {
108 $treeItems[] = $this->renderNode($node, $recursive);
109 }
110 return $treeItems;
111 }
112 }