ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Renderer.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2016 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
6
8use ILIAS\UI\Renderer as RendererInterface;
10
15 public function render(Component\Component $component, RendererInterface $default_renderer) {
16 $this->checkComponent($component);
17
18 if ($component instanceof Component\Button\Close) {
19 return $this->render_close($component);
20 }
21 else {
22 return $this->render_button($component, $default_renderer);
23 }
24 }
25
26 protected function render_button(Component\Component $component, RendererInterface $default_renderer) {
27 // TODO: Tt would be nice if we could use <button> for rendering a button
28 // instead of <a>. This was not done atm, as there is no attribute on a
29 // button to make it open an URL. This would require JS.
30
31 if ($component instanceof Component\Button\Primary) {
32 $tpl_name = "tpl.primary.html";
33 }
34 if ($component instanceof Component\Button\Standard) {
35 $tpl_name = "tpl.standard.html";
36 }
37
38 $tpl = $this->getTemplate($tpl_name, true, true);
39 $action = $component->getAction();
40 // The action is always put in the data-action attribute to have it available
41 // on the client side, even if it is not available on rendering.
42 $tpl->setVariable("ACTION", $action);
43 $label = $component->getLabel();
44 if ($label !== null) {
45 $tpl->setVariable("LABEL", $component->getLabel());
46 }
47 if ($component->isActive()) {
48 $tpl->setCurrentBlock("with_href");
49 $tpl->setVariable("HREF", $action);
50 $tpl->parseCurrentBlock();
51 }
52 else {
53 $tpl->touchBlock("disabled");
54 }
55
56 $this->maybe_render_id($component, $tpl);
57
58 return $tpl->get();
59 }
60
61 protected function render_close($component) {
62 $tpl = $this->getTemplate("tpl.close.html", true, true);
63 // This is required as the rendering seems to only create any output at all
64 // if any var was set or block was touched.
65 $tpl->setVariable("FORCE_RENDERING", "");
66 $this->maybe_render_id($component, $tpl);
67 return $tpl->get();
68 }
69
70 protected function maybe_render_id($component, $tpl) {
71 $id = $this->bindJavaScript($component);
72 if ($id !== null) {
73 $tpl->setCurrentBlock("with_id");
74 $tpl->setVariable("ID", $id);
75 $tpl->parseCurrentBlock();
76 }
77 }
78
82 protected function getComponentInterfaceName() {
83 return array
84 ( Component\Button\Primary::class
85 , Component\Button\Standard::class
86 , Component\Button\Close::class
87 );
88 }
89}
global $tpl
Definition: ilias.php:8
An exception for terminatinating execution or to throw for unit testing.
This implements commonalities between standard and primary buttons.
Definition: Button.php:15
render(Component\Component $component, RendererInterface $default_renderer)
@inheritdocs
Definition: Renderer.php:15
render_button(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:26
getTemplate($name, $purge_unfilled_vars, $purge_unused_blocks)
Get template of component this renderer is made for.
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.
checkComponent(Component $component)
Check if a given component fits this renderer and throw \LogicError if that is not the case.
A component is the most general form of an entity in the UI.
Definition: Component.php:13
An entity that renders components to a string output.
Definition: Renderer.php:12