ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
Renderer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\UI\Renderer as RendererInterface;
27
29{
33 public function render(Component\Component $component, RendererInterface $default_renderer): string
34 {
35 if (!$component instanceof Glyph) {
36 $this->cannotHandleComponent($component);
37 }
38
39 $tpl = $this->getTemplate("tpl.glyph.standard.html", true, true);
40
41 if ($component->isHighlighted()) {
42 $tpl->touchBlock("highlighted");
43 }
44
45 $label = $component->getLabel();
46 if ('' !== $label) {
47 $tpl->touchBlock('with_aria_label');
48 // @todo: move translation to factory, this breaks custom labels...
49 $tpl->setVariable("LABEL", $this->txt($label));
50 $tpl->touchBlock('with_role');
51 } else {
52 // glyph must be hidden if there is no label (semantic meaning)
53 $tpl->touchBlock('with_aria_hidden');
54 }
55
56 $id = $this->bindJavaScript($component);
57
58 if ($id !== null) {
59 $tpl->setCurrentBlock("with_id");
60 $tpl->setVariable("ID", $id);
61 $tpl->parseCurrentBlock();
62 }
63 $tpl->setVariable("GLYPH", $this->getInnerGlyphHTML($component, $default_renderer));
64 return $tpl->get();
65 }
66
67 protected function getInnerGlyphHTML(Component\Component $component, RendererInterface $default_renderer): string
68 {
69 $tpl = $this->getTemplate('tpl.glyph.html', true, true);
70
71 $tpl->touchBlock($component->getType());
72
73 $largest_counter = 0;
74 foreach ($component->getCounters() as $counter) {
75 if ($largest_counter < $counter->getNumber()) {
76 $largest_counter = $counter->getNumber();
77 }
78 $n = "counter_" . $counter->getType();
79 $tpl->setCurrentBlock($n);
80 $tpl->setVariable(strtoupper($n), $default_renderer->render($counter));
81 $tpl->parseCurrentBlock();
82 }
83
84 if ($largest_counter) {
85 $tpl->setCurrentBlock("counter_spacer");
86 $tpl->setVariable("COUNTER_SPACER", $largest_counter);
87 $tpl->parseCurrentBlock();
88 }
89 return $tpl->get();
90 }
91}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
render(Component\Component $component, RendererInterface $default_renderer)
@inheritdocs
Definition: Renderer.php:33
getInnerGlyphHTML(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:67
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.
Interface to templating as it is used in the UI framework.
Definition: Template.php:29
An entity that renders components to a string output.
Definition: Renderer.php:31
$counter