ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Renderer.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use ILIAS\Data\URI;
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 
41  $tpl_name = "tpl.node.html";
42  $tpl = $this->getTemplate($tpl_name, true, true);
43 
44  $async = false;
45  if ($component instanceof Node\AsyncNode && $component->getAsyncLoading()) {
46  $tpl->setVariable("ASYNCURL", $component->getAsyncURL());
47  $async = true;
48  }
49 
50  $icon = $component->getIcon();
51  $label = $component->getLabel();
52 
53  if (!is_null($icon) && $icon->getLabel() === $label) {
54  $icon->setLabel("");
55  }
56 
58  $link = $component->getLink();
59 
60  if (null !== $link) {
61  $linkAsString = $link->__toString();
62 
63  $tpl->setVariable("LINK", $linkAsString);
64  $tpl->setVariable("LABEL_LINKED", $label);
65  if ($icon) {
66  $tpl->setVariable("ICON_LINKED", $default_renderer->render($icon));
67  }
68  if ($component instanceof Node\Bylined && null !== $component->getByline()) {
69  $tpl->setVariable('BYLINE_LINKED', $component->getByline());
70  } elseif ($component instanceof Node\KeyValue && null !== $component->getValue()) {
71  $tpl->setVariable('VALUE_LINKED', $component->getValue());
72  }
73  } else {
74  $tpl->setCurrentBlock("node_without_link");
75  $tpl->setVariable("LABEL", $label);
76  if ($icon) {
77  $tpl->setVariable("ICON", $default_renderer->render($icon));
78  }
79  if ($component instanceof Node\Bylined && null !== $component->getByline()) {
80  $tpl->setVariable('BYLINE', $component->getByline());
81  } elseif ($component instanceof Node\KeyValue && null !== $component->getValue()) {
82  $tpl->setVariable('VALUE', $component->getValue());
83  }
84  }
85 
86  if ($component->isHighlighted()) {
87  $tpl->touchBlock("highlighted");
88  }
89 
93  $triggered_signals = $component->getTriggeredSignals();
94  if (count($triggered_signals) > 0) {
95  $component = $this->triggerFurtherSignals($component, $triggered_signals);
96  }
97 
98  $id = $this->bindJavaScript($component);
99  if ($id) {
100  $tpl->setCurrentBlock("li_id");
101  $tpl->setVariable("ID", $id);
102  $tpl->parseCurrentBlock();
103  }
104 
105 
106  $subnodes = $component->getSubnodes();
107 
108  if (count($subnodes) > 0 || $async) {
109  $tpl->touchBlock("expandable");
110  $tpl->setCurrentBlock("aria_expanded");
111  if ($component->isExpanded()) {
112  $tpl->setVariable("ARIA_EXPANDED", "true");
113  } else {
114  $tpl->setVariable("ARIA_EXPANDED", "false");
115  }
116  $tpl->parseCurrentBlock();
117 
118  $subnodes_html = $default_renderer->render($subnodes);
119  $tpl->setVariable("SUBNODES", $subnodes_html);
120  }
121 
122  if ($async || $link === null || count($subnodes) !== 0) {
123  $tpl->touchBlock("role_item");
124  } else {
125  $tpl->touchBlock("role_none");
126  }
127 
128  return $tpl->get();
129  }
130 
136  protected function triggerFurtherSignals(
137  Node\Node $component,
138  array $triggered_signals
140  $signals = [];
141  foreach ($triggered_signals as $s) {
145  $signals[] = [
146  "signal_id" => $s->getSignal()->getId(),
147  "event" => $s->getEvent(),
148  "options" => $s->getSignal()->getOptions()
149  ];
150  }
151  $signals = json_encode($signals);
152 
153  return $component->withAdditionalOnLoadCode(fn($id) => "
154  $('#$id > span').click(function(e){
155  var node = $('#$id'),
156  signals = $signals;
157 
158  for (var i = 0; i < signals.length; i++) {
159  var s = signals[i];
160  node.trigger(s.signal_id, s);
161  }
162 
163  return false;
164  });");
165  }
166 }
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
This describes a Tree Node.
Definition: Node.php:30
This describes a Tree Node.
Definition: AsyncNode.php:26
This describes a tree node with an byline providing additional information about this node...
Definition: Bylined.php:27
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
cannotHandleComponent(Component $component)
This method MUST be called by derived component renderers, if.
render(Component $component, Renderer $default_renderer)
Render the component if possible and delegate additional rendering to the default_renderer.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This describes a tree node in which the label is complemented by an additional string, forming a key-value pair.
Definition: KeyValue.php:25
getAsyncLoading()
Should this node load its children asynchronously?
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.