ILIAS  release_8 Revision v8.24
Renderer.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
25use ILIAS\UI\Renderer as RendererInterface;
27use LogicException;
28
30{
34 public function render(Component\Component $component, RendererInterface $default_renderer): string
35 {
36 $this->checkComponent($component);
37
38 if ($component instanceof Component\Link\Standard) {
39 return $this->renderStandard($component);
40 }
41 if ($component instanceof Component\Link\Bulky) {
42 return $this->renderBulky($component, $default_renderer);
43 }
44 throw new LogicException("Cannot render: " . get_class($component));
45 }
46
47 protected function setStandardVars(
48 string $tpl_name,
49 Component\Link\Link $component
50 ): Template {
51 $tpl = $this->getTemplate($tpl_name, true, true);
52 $action = $component->getAction();
53 $label = $component->getLabel();
54 if ($component->getOpenInNewViewport()) {
55 $tpl->touchBlock("open_in_new_viewport");
56 }
57 $tpl->setVariable("LABEL", $label);
58 $tpl->setVariable("HREF", $action);
59 return $tpl;
60 }
61
62 protected function renderStandard(
63 Component\Link\Standard $component
64 ): string {
65 $tpl_name = "tpl.standard.html";
66 $tpl = $this->setStandardVars($tpl_name, $component);
67 return $tpl->get();
68 }
69
70 protected function renderBulky(
71 Component\Link\Bulky $component,
72 RendererInterface $default_renderer
73 ): string {
74 $tpl_name = "tpl.bulky.html";
75 $tpl = $this->setStandardVars($tpl_name, $component);
76 $renderer = $default_renderer->withAdditionalContext($component);
77 $tpl->setVariable("SYMBOL", $renderer->render($component->getSymbol()));
78 $id = $this->bindJavaScript($component);
79 $tpl->setVariable("ID", $id);
80
81 $aria_role = $component->getAriaRole();
82 if ($aria_role != null) {
83 $tpl->setCurrentBlock("with_aria_role");
84 $tpl->setVariable("ARIA_ROLE", $aria_role);
85 $tpl->parseCurrentBlock();
86 }
87
88 return $tpl->get();
89 }
90
94 protected function getComponentInterfaceName(): array
95 {
96 return [
97 Component\Link\Standard::class,
98 Component\Link\Bulky::class
99 ];
100 }
101}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
checkComponent(Component $component)
Check if a given component fits this renderer and throw \LogicError if that is not the case.
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
return true
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
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...