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{
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
46 $tpl_file = $this->getTemplateFilename();
47 $tpl = $this->getTemplate($tpl_file, true, true);
48
49 $tpl = $this->renderAction($component, $tpl);
50
51 if ($component->isTabbable() && !$this instanceof ButtonContextRenderer) { // Buttons are already tabbable itself
52 $tpl->touchBlock("tabbable");
53 }
54
55 if ($component->isHighlighted()) {
56 $tpl->touchBlock("highlighted");
57 }
58
59 if (!$component->isActive()) {
60 $tpl->touchBlock("disabled");
61
62 $tpl->setCurrentBlock("with_aria_disabled");
63 $tpl->setVariable("ARIA_DISABLED", "true");
64 $tpl->parseCurrentBlock();
65 }
66
67 $tpl = $this->renderLabel($component, $tpl);
68
69 $id = $this->bindJavaScript($component);
70
71 if ($id !== null) {
72 $tpl->setCurrentBlock("with_id");
73 $tpl->setVariable("ID", $id);
74 $tpl->parseCurrentBlock();
75 }
76
77 $tpl->setVariable("GLYPH", $this->getInnerGlyphHTML($component, $default_renderer));
78 return $tpl->get();
79 }
80
81 protected function renderLabel(Component\Component $component, Template $tpl): Template
82 {
83 $tpl->setVariable("LABEL", $this->txt($component->getLabel()));
84 return $tpl;
85 }
86
87 protected function renderAction(Component\Component $component, Template $tpl): Template
88 {
89 $action = $component->getAction();
90 if ($component->isActive() && $action !== null) {
91 $tpl->setCurrentBlock("with_action");
92 $tpl->setVariable("ACTION", $component->getAction());
93 $tpl->parseCurrentBlock();
94 }
95 return $tpl;
96 }
97
98 protected function getInnerGlyphHTML(Component\Component $component, RendererInterface $default_renderer): string
99 {
100 $tpl = $this->getTemplate('tpl.glyph.html', true, true);
101
102 $tpl->touchBlock($component->getType());
103
104 $largest_counter = 0;
105 foreach ($component->getCounters() as $counter) {
106 if ($largest_counter < $counter->getNumber()) {
107 $largest_counter = $counter->getNumber();
108 }
109 $n = "counter_" . $counter->getType();
110 $tpl->setCurrentBlock($n);
111 $tpl->setVariable(strtoupper($n), $default_renderer->render($counter));
112 $tpl->parseCurrentBlock();
113 }
114
115 if ($largest_counter) {
116 $tpl->setCurrentBlock("counter_spacer");
117 $tpl->setVariable("COUNTER_SPACER", $largest_counter);
118 $tpl->parseCurrentBlock();
119 }
120 return $tpl->get();
121 }
122}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
renderLabel(Component\Component $component, Template $tpl)
Definition: Renderer.php:81
render(Component\Component $component, RendererInterface $default_renderer)
@inheritdocs
Definition: Renderer.php:40
getInnerGlyphHTML(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:98
renderAction(Component\Component $component, Template $tpl)
Definition: Renderer.php:87
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 symbol.
Definition: Symbol.php:30
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