ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
Renderer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use ILIAS\UI\Renderer as RendererInterface;
29
31{
35 public function render(Component\Component $component, RendererInterface $default_renderer): string
36 {
37 if (!$component instanceof Node\Node) {
38 $this->cannotHandleComponent($component);
39 }
40
42 $component = $this->addTriggererOnLoadCode($component);
43
44 $tpl_name = "tpl.node.html";
45 $tpl = $this->getTemplate($tpl_name, true, true);
46
47 $async = false;
48 if ($component instanceof Node\AsyncNode && $component->getAsyncLoading()) {
49 $tpl->setVariable("ASYNCURL", $component->getAsyncURL());
50 $async = true;
51 }
52
53 $icon = $component->getIcon();
54 $label = $component->getLabel();
55
56 if (!is_null($icon) && $icon->getLabel() === $label) {
57 $icon->setLabel("");
58 }
59
61 $link = $component->getLink();
62
63 if (null !== $link) {
64 $linkAsString = $link->__toString();
65
66 $tpl->setVariable("LINK", $linkAsString);
67 $tpl->setVariable("LABEL_LINKED", $label);
68 if ($icon) {
69 $tpl->setVariable("ICON_LINKED", $default_renderer->render($icon));
70 }
71 if ($component instanceof Node\Bylined && null !== $component->getByline()) {
72 $tpl->setVariable('BYLINE_LINKED', $component->getByline());
73 } elseif ($component instanceof Node\KeyValue && null !== $component->getValue()) {
74 $tpl->setVariable('VALUE_LINKED', $component->getValue());
75 }
76 } else {
77 $tpl->setCurrentBlock("node_without_link");
78 $tpl->setVariable("LABEL", $label);
79 if ($icon) {
80 $tpl->setVariable("ICON", $default_renderer->render($icon));
81 }
82 if ($component instanceof Node\Bylined && null !== $component->getByline()) {
83 $tpl->setVariable('BYLINE', $component->getByline());
84 } elseif ($component instanceof Node\KeyValue && null !== $component->getValue()) {
85 $tpl->setVariable('VALUE', $component->getValue());
86 }
87 }
88
89 if ($component->isHighlighted()) {
90 $tpl->touchBlock("highlighted");
91 }
92
96 $triggered_signals = $component->getTriggeredSignals();
97 if (count($triggered_signals) > 0) {
98 $component = $this->triggerFurtherSignals($component, $triggered_signals);
99 }
100
101 $id = $this->bindJavaScript($component);
102 if ($id) {
103 $tpl->setCurrentBlock("li_id");
104 $tpl->setVariable("ID", $id);
105 $tpl->parseCurrentBlock();
106 }
107
108
109 $subnodes = $component->getSubnodes();
110
111 if (count($subnodes) > 0 || $async) {
112 $tpl->touchBlock("expandable");
113 $tpl->setCurrentBlock("aria_expanded");
114 if ($component->isExpanded()) {
115 $tpl->setVariable("ARIA_EXPANDED", "true");
116 } else {
117 $tpl->setVariable("ARIA_EXPANDED", "false");
118 }
119 $tpl->parseCurrentBlock();
120
121 $subnodes_html = $default_renderer->render($subnodes);
122 $tpl->setVariable("SUBNODES", $subnodes_html);
123 }
124
125 if ($async || $link === null || count($subnodes) !== 0) {
126 $tpl->touchBlock("role_item");
127 } else {
128 $tpl->touchBlock("role_none");
129 }
130
131 return $tpl->get();
132 }
133
139 protected function triggerFurtherSignals(
140 Node\Node $component,
141 array $triggered_signals
143 $signals = [];
144 foreach ($triggered_signals as $s) {
148 $signals[] = [
149 "signal_id" => $s->getSignal()->getId(),
150 "event" => $s->getEvent(),
151 "options" => $s->getSignal()->getOptions()
152 ];
153 }
154 $signals = json_encode($signals);
155
156 return $component->withAdditionalOnLoadCode(fn($id) => "
157 $('#$id > span').click(function(e){
158 var node = $('#$id'),
159 signals = $signals;
160
161 for (var i = 0; i < signals.length; i++) {
162 var s = signals[i];
163 node.trigger(s.signal_id, s);
164 }
165
166 return false;
167 });");
168 }
169}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
cannotHandleComponent(Component $component)
This method MUST be called by derived component renderers, if.
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.
addTriggererOnLoadCode(Triggerer $triggerer)
Add onload-code for triggerer.
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
Interface to be extended by components that have the possibility to bind to Javascript.
This describes a Tree Node.
Definition: AsyncNode.php:27
getAsyncLoading()
Should this node load its children asynchronously?
This describes a tree node with an byline providing additional information about this node.
Definition: Bylined.php:28
getByline()
The byline string that will be displayed as additional information to the current node.
This describes a tree node in which the label is complemented by an additional string,...
Definition: KeyValue.php:26
getValue()
The value string that will be displayed behind the label of the node.
This describes a Tree Node.
Definition: Node.php:31
render(Component $component, Renderer $default_renderer)
Render the component if possible and delegate additional rendering to the default_renderer.
An entity that renders components to a string output.
Definition: Renderer.php:31