ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
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 $tpl->setVariable("LABEL", $label);
49 $tpl->touchBlock('with_role');
50 } else {
51 // glyph must be hidden if there is no label (semantic meaning)
52 $tpl->touchBlock('with_aria_hidden');
53 }
54
55 $id = $this->bindJavaScript($component);
56
57 if ($id !== null) {
58 $tpl->setCurrentBlock("with_id");
59 $tpl->setVariable("ID", $id);
61 }
62 $tpl->setVariable("GLYPH", $this->getInnerGlyphHTML($component, $default_renderer));
63 return $tpl->get();
64 }
65
66 protected function getInnerGlyphHTML(Component\Component $component, RendererInterface $default_renderer): string
67 {
68 $tpl = $this->getTemplate('tpl.glyph.html', true, true);
69
70 $tpl->touchBlock($component->getType());
71
72 $largest_counter = 0;
73 foreach ($component->getCounters() as $counter) {
74 if ($largest_counter < $counter->getNumber()) {
75 $largest_counter = $counter->getNumber();
76 }
77 $n = "counter_" . $counter->getType();
79 $tpl->setVariable(strtoupper($n), $default_renderer->render($counter));
81 }
82
83 if ($largest_counter) {
84 $tpl->setCurrentBlock("counter_spacer");
85 $tpl->setVariable("COUNTER_SPACER", $largest_counter);
87 }
88 return $tpl->get();
89 }
90}
$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:66
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.
setVariable(string $variable, $value='')
Sets the given variable to the given value.
touchBlock(string $block)
overwrites ITX::touchBlock.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
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
readonly ilGlobalTemplateInterface $tpl