ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Renderer.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2017 Alexander Killing <killing@leifos.de> Extended GPL, see docs/LICENSE */
4
6
8use ILIAS\UI\Renderer as RendererInterface;
11
13{
17 public function render(Component\Component $component, RendererInterface $default_renderer)
18 {
19 $this->checkComponent($component);
20
21 return $this->renderDropdown($component, $default_renderer);
22 }
23
24 protected function renderDropdown(Component\Dropdown\Dropdown $component, RendererInterface $default_renderer)
25 {
26
27 // get template
28 $tpl_name = "tpl.standard.html";
29 $tpl = $this->getTemplate($tpl_name, true, true);
30
31 // render items
32 $items = $component->getItems();
33 if (count($items) == 0) {
34 return "";
35 }
36 $this->renderItems($items, $tpl, $default_renderer);
37
38 // render trigger button
39 $label = $component->getLabel();
40 if ($label !== null) {
41 $tpl->setVariable("LABEL", $component->getLabel());
42 } else {
43 $tpl->setVariable("LABEL", "");
44 }
45
46 $this->maybeRenderId($component, $tpl, "with_id", "ID");
47
48 return $tpl->get();
49 }
50
55 protected function renderItems($items, $tpl, $default_renderer)
56 {
57 foreach ($items as $item) {
58 $tpl->setCurrentBlock("item");
59 $tpl->setVariable("ITEM", $default_renderer->render($item));
60 $tpl->parseCurrentBlock();
61 }
62 }
63
64
65 protected function maybeRenderId(Component\Component $component, $tpl, $block, $template_var)
66 {
67 $id = $this->bindJavaScript($component);
68 if ($id !== null) {
69 $tpl->setCurrentBlock($block);
70 $tpl->setVariable($template_var, $id);
71 $tpl->parseCurrentBlock();
72 }
73 }
74
75
83 public function withBlocksToBeTouched($block)
84 {
85 assert(is_string($block));
86 $clone = clone $this;
87 $clone->touch_blocks[] = $block;
88 return $clone;
89 }
90
91
95 public function registerResources(ResourceRegistry $registry)
96 {
97 parent::registerResources($registry);
98 $registry->register('./src/UI/templates/js/Dropdown/dropdown.js');
99 }
100
104 protected function getComponentInterfaceName()
105 {
106 return array(Component\Dropdown\Standard::class
107 );
108 }
109}
$tpl
Definition: ilias.php:10
An exception for terminatinating execution or to throw for unit testing.
This implements commonalities between different types of Dropdowns.
Definition: Dropdown.php:17
getComponentInterfaceName()
Get the name of the component-interface this renderer is supposed to render.ATTENTION: Fully qualifie...
Definition: Renderer.php:104
maybeRenderId(Component\Component $component, $tpl, $block, $template_var)
Definition: Renderer.php:65
renderItems($items, $tpl, $default_renderer)
Definition: Renderer.php:55
registerResources(ResourceRegistry $registry)
Announce resources this renderer requires.null
Definition: Renderer.php:95
withBlocksToBeTouched($block)
Append a block to touch during rendering and return cloned instance.
Definition: Renderer.php:83
renderDropdown(Component\Dropdown\Dropdown $component, RendererInterface $default_renderer)
Definition: Renderer.php:24
render(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:17
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.
if(!array_key_exists('StateId', $_REQUEST)) $id
A component is the most general form of an entity in the UI.
Definition: Component.php:14
Registry for resources required by rendered output like Javascript or CSS.
An entity that renders components to a string output.
Definition: Renderer.php:15