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
24use ILIAS\UI\Renderer as RendererInterface;
28
30{
31 protected function getTemplateFilename(): string
32 {
33 return "tpl.glyph.standard.html";
34 }
35
36
40 public function render(Component\Component $component, RendererInterface $default_renderer): string
41 {
42 if (!$component instanceof Component\Symbol\Glyph\Glyph) {
43 $this->cannotHandleComponent($component);
44 }
45
47 $component = $this->addTriggererOnLoadCode($component);
48
49 $tpl_file = $this->getTemplateFilename();
50 $tpl = $this->getTemplate($tpl_file, true, true);
51
52 $tpl = $this->renderAction($component, $tpl);
53
54 if ($component->isTabbable() && !$this instanceof ButtonContextRenderer) { // Buttons are already tabbable itself
55 $tpl->touchBlock("tabbable");
56 }
57
58 if ($component->isHighlighted()) {
59 $tpl->touchBlock("highlighted");
60 }
61
62 if (!$component->isActive()) {
63 $tpl->touchBlock("disabled");
64
65 $tpl->setCurrentBlock("with_aria_disabled");
66 $tpl->setVariable("ARIA_DISABLED", "true");
67 $tpl->parseCurrentBlock();
68 }
69
70 $tpl = $this->renderLabel($component, $tpl);
71
72 $id = $this->bindJavaScript($component);
73
74 if ($id !== null) {
75 $tpl->setCurrentBlock("with_id");
76 $tpl->setVariable("ID", $id);
77 $tpl->parseCurrentBlock();
78 }
79
80 $tpl->setVariable("GLYPH", $this->getInnerGlyphHTML($component, $default_renderer));
81 return $tpl->get();
82 }
83
84 protected function renderLabel(Component\Component $component, Template $tpl): Template
85 {
86 $tpl->setVariable("LABEL", $this->txt($component->getLabel()));
87 return $tpl;
88 }
89
90 protected function renderAction(Component\Component $component, Template $tpl): Template
91 {
92 $action = $component->getAction();
93 if ($component->isActive() && $action !== null) {
94 $tpl->setCurrentBlock("with_action");
95 $tpl->setVariable("ACTION", $component->getAction());
96 $tpl->parseCurrentBlock();
97 }
98 return $tpl;
99 }
100
101 protected function getInnerGlyphHTML(Component\Component $component, RendererInterface $default_renderer): string
102 {
103 $tpl = $this->getTemplate('tpl.glyph.html', true, true);
104
105 $tpl->touchBlock($component->getType());
106
107 $largest_counter = 0;
108 foreach ($component->getCounters() as $counter) {
109 if ($largest_counter < $counter->getNumber()) {
110 $largest_counter = $counter->getNumber();
111 }
112 $n = "counter_" . $counter->getType();
113 $tpl->setCurrentBlock($n);
114 $tpl->setVariable(strtoupper($n), $default_renderer->render($counter));
115 $tpl->parseCurrentBlock();
116 }
117
118 if ($largest_counter) {
119 $tpl->setCurrentBlock("counter_spacer");
120 $tpl->setVariable("COUNTER_SPACER", $largest_counter);
121 $tpl->parseCurrentBlock();
122 }
123 return $tpl->get();
124 }
125}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
renderLabel(Component\Component $component, Template $tpl)
Definition: Renderer.php:84
getInnerGlyphHTML(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:101
renderAction(Component\Component $component, Template $tpl)
Definition: Renderer.php:90
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.
This describes a symbol.
Definition: Symbol.php:30
render(Component $component, Renderer $default_renderer)
Render the component if possible and delegate additional rendering to the default_renderer.
Registry for resources required by rendered output like Javascript or CSS.
Interface to templating as it is used in the UI framework.
Definition: Template.php:29
setVariable(string $name, $value)
Set a variable in the current block.
setCurrentBlock(string $name)
Set the block to work on.
parseCurrentBlock()
Parse the block that is currently worked on.
An entity that renders components to a string output.
Definition: Renderer.php:31
$counter