ILIAS  release_7 Revision v7.30-3-g800a261c036
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
9use ILIAS\UI\Renderer as RendererInterface;
12use \ILIAS\UI\Implementation\Render\Template;
14
16{
20 public function render(Component\Component $component, RendererInterface $default_renderer)
21 {
22 $this->checkComponent($component);
23
27 return $this->renderDropdown($component, $default_renderer);
28 }
29
30 protected function renderDropdown(Dropdown $component, RendererInterface $default_renderer)
31 {
32
33 // get template
34 $tpl_name = "tpl.standard.html";
35 $tpl = $this->getTemplate($tpl_name, true, true);
36
37 // render items
38 $items = $component->getItems();
39 if (is_array($items) && count($items) == 0) {
40 return "";
41 }
42 $this->renderItems($items, $tpl, $default_renderer);
43
44 // render trigger button
45 $label = $component->getLabel();
46 if ($label !== null) {
47 $tpl->setVariable("LABEL", $component->getLabel());
48 } else {
49 $tpl->setVariable("LABEL", "");
50 }
51
52 // ensure that a) a separate aria label may be provided and
53 // b) that an empty label and empty aria-label will use the "actions" fallback
54 if ($component->getLabel() == "" || $component->getAriaLabel() != "") {
55 $aria_label = ($component->getAriaLabel() != "")
56 ? $component->getAriaLabel()
57 : $this->txt("actions");
58 $tpl->setCurrentBlock("aria_label");
59 $tpl->setVariable("ARIA_LABEL", $aria_label);
60 $tpl->parseCurrentBlock();
61 }
62
63 $this->maybeRenderId($component, $tpl, "with_id", "ID");
64
65 return $tpl->get();
66 }
67
68 protected function renderItems(array $items, Template $tpl, RendererInterface $default_renderer)
69 {
70 foreach ($items as $item) {
71 $tpl->setCurrentBlock("item");
72 $tpl->setVariable("ITEM", $default_renderer->render($item));
73 $tpl->parseCurrentBlock();
74 }
75 }
76
77
78 protected function maybeRenderId(JavaScriptBindable $component, Template $tpl, $block, $template_var)
79 {
80 $id = $this->bindJavaScript($component);
81 if ($id !== null) {
82 $tpl->setCurrentBlock($block);
83 $tpl->setVariable($template_var, $id);
84 $tpl->parseCurrentBlock();
85 }
86 }
87
91 public function registerResources(ResourceRegistry $registry)
92 {
93 parent::registerResources($registry);
94 $registry->register('./src/UI/templates/js/Dropdown/dropdown.js');
95 }
96
100 protected function getComponentInterfaceName()
101 {
102 return array(Component\Dropdown\Standard::class
103 );
104 }
105}
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:100
renderItems(array $items, Template $tpl, RendererInterface $default_renderer)
Definition: Renderer.php:68
registerResources(ResourceRegistry $registry)
Announce resources this renderer requires.null
Definition: Renderer.php:91
maybeRenderId(JavaScriptBindable $component, Template $tpl, $block, $template_var)
Definition: Renderer.php:78
renderDropdown(Dropdown $component, RendererInterface $default_renderer)
Definition: Renderer.php:30
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:14
Interface to be extended by components that have the possibility to bind to Javascript.
render(Component $component, Renderer $default_renderer)
Render the component if possible and delegate additional rendering to the default_renderer.
Registry for resources required by rendered output like Javascript or CSS.
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
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.