ILIAS  release_7 Revision v7.30-3-g800a261c036
Renderer.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5/* Copyright (c) 2017 Alexander Killing <killing@leifos.de> Extended GPL, see docs/LICENSE */
6
8
11use ILIAS\UI\Renderer as RendererInterface;
13
15{
19 public function render(Component\Component $component, RendererInterface $default_renderer)
20 {
21 $this->checkComponent($component);
22
23 if ($component instanceof Component\Link\Standard) {
24 return $this->renderStandard($component, $default_renderer);
25 }
26 if ($component instanceof Component\Link\Bulky) {
27 return $this->renderBulky($component, $default_renderer);
28 }
29 }
30
31 protected function setStandardVars(
32 string $tpl_name,
33 Component\Link\Link $component
34 ) : Template {
35 $tpl = $this->getTemplate($tpl_name, true, true);
36 $action = $component->getAction();
37 $label = $component->getLabel();
38 if ($component->getOpenInNewViewport()) {
39 $tpl->touchBlock("open_in_new_viewport");
40 }
41 $tpl->setVariable("LABEL", $label);
42 $tpl->setVariable("HREF", $action);
43 return $tpl;
44 }
45
46 protected function renderStandard(
47 Component\Link\Standard $component,
48 RendererInterface $default_renderer
49 ) : string {
50 $tpl_name = "tpl.standard.html";
51 $tpl = $this->setStandardVars($tpl_name, $component);
52 return $tpl->get();
53 }
54
55 protected function renderBulky(
56 Component\Link\Bulky $component,
57 RendererInterface $default_renderer
58 ) : string {
59 $tpl_name = "tpl.bulky.html";
60 $tpl = $this->setStandardVars($tpl_name, $component);
61 $renderer = $default_renderer->withAdditionalContext($component);
62 $tpl->setVariable("SYMBOL", $renderer->render($component->getSymbol()));
63
64 $id = $this->bindJavaScript($component);
65 $tpl->setVariable("ID", $id);
66
67 $aria_role = $component->getAriaRole();
68 if ($aria_role != null) {
69 $tpl->setCurrentBlock("with_aria_role");
70 $tpl->setVariable("ARIA_ROLE", $aria_role);
71 $tpl->parseCurrentBlock();
72 }
73
74 return $tpl->get();
75 }
76
80 protected function getComponentInterfaceName()
81 {
82 return [
83 Component\Link\Standard::class,
84 Component\Link\Bulky::class
85 ];
86 }
87}
An exception for terminatinating execution or to throw for unit testing.
getTemplate($name, $purge_unfilled_vars, $purge_unused_blocks)
Get template of component this renderer is made for.
checkComponent(Component $component)
Check if a given component fits this renderer and throw \LogicError if that is not the case.
return true
Flag indicating whether or not HTTP headers will be sent when outputting captcha image/audio.
A component is the most general form of an entity in the UI.
Definition: Component.php:14
Interface to templating as it is used in the UI framework.
Definition: Template.php:14
An entity that renders components to a string output.
Definition: Renderer.php:15
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41