ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Renderer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\UI\Renderer as RendererInterface;
28
30{
34 public function render(Component\Component $component, RendererInterface $default_renderer): string
35 {
36 if (!$component instanceof Tree\Expandable) {
37 $this->cannotHandleComponent($component);
38 }
39
40 $tpl_name = "tpl.tree.html";
41 $tpl = $this->getTemplate($tpl_name, true, true);
42
43 $tpl->setVariable("ARIA_LABEL", $component->getLabel());
44
45 $nodes = [];
46 foreach ($component->getData() as $record) {
47 $nodes[] = $this->buildNode(
48 $component->getRecursion(),
49 $record,
50 $component->getEnvironment()
51 );
52 }
53
54 $nodes_html = $default_renderer->render($nodes);
55
56 if ($component->isSubTree()) {
57 return $nodes_html;
58 }
59
60 $tpl->setVariable('NODES', $nodes_html);
61
62 $highlight_node_on_click = $component->getHighlightOnNodeClick();
63 $component = $component->withAdditionalOnLoadCode(
64 fn($id) => "il.UI.tree.init('$id', $highlight_node_on_click)"
65 );
66
67 $id = $this->bindJavaScript($component);
68 $tpl->setVariable("ID", $id);
69
70
71 return $tpl->get();
72 }
73
78 protected function buildNode(
79 Tree\TreeRecursion $recursion,
80 $record,
81 $environment
82 ): Tree\Node\Node {
83 $node = $recursion->build(
84 $this->getUIFactory()->tree()->node(),
85 $record,
86 $environment
87 );
88
89 foreach ($recursion->getChildren($record, $environment) as $sub_record) {
90 $node = $node->withAdditionalSubnode(
91 $this->buildNode($recursion, $sub_record, $environment)
92 );
93 }
94
95 return $node;
96 }
97
101 public function registerResources(ResourceRegistry $registry): void
102 {
103 parent::registerResources($registry);
104 $registry->register('assets/js/tree.js');
105 }
106}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
buildNode(Tree\TreeRecursion $recursion, $record, $environment)
Trigger TreeRecursion::build and recurse into hierarchy by checking for further children of the recor...
Definition: Renderer.php:78
registerResources(ResourceRegistry $registry)
Announce resources this renderer requires.
Definition: Renderer.php:101
render(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:34
cannotHandleComponent(Component $component)
This method MUST be called by derived component renderers, if.
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
This describes a Tree Control.
Definition: Expandable.php:29
Interface for mapping data-structures to the Tree.
This describes a Tree Control.
Definition: Tree.php:29
Registry for resources required by rendered output like Javascript or CSS.
register(string $name)
Add a dependency.
An entity that renders components to a string output.
Definition: Renderer.php:31