ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
Renderer.php
Go to the documentation of this file.
1<?php
2declare(strict_types=1);
3
4/* Copyright (c) 2019 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
5
7
9use ILIAS\UI\Renderer as RendererInterface;
12
14{
18 public function render(Component\Component $component, RendererInterface $default_renderer)
19 {
20 $this->checkComponent($component);
21
22 $html = $this->renderMenu($component, $default_renderer);
23
24 if ($component instanceof Menu\Drilldown) {
25 $tpl_name = "tpl.drilldown.html";
26 $tpl = $this->getTemplate($tpl_name, true, true);
27 $tpl->setVariable('DRILLDOWN', $html);
28
29 $component = $component->withAdditionalOnLoadCode(function ($id) {
30 return "il.UI.menu.drilldown.init('$id');";
31 });
32 $id = $this->bindJavaScript($component);
33 $tpl->setVariable("ID", $id);
34
35 return $tpl->get();
36 }
37
38 return $html;
39 }
40
47 protected function renderMenu(
48 Menu\Menu $component,
49 RendererInterface $default_renderer
50 ) : string {
51 $tpl_name = "tpl.menuitem.html";
52 $tpl = $this->getTemplate($tpl_name, true, true);
53
54 $label = $this->maybeConvertLabelToShy($component->getLabel());
55 $tpl->setVariable('LABEL', $default_renderer->render($label));
56
57 if ($component instanceof Menu\Sub) {
58 if ($component->isInitiallyActive()) {
59 $tpl->touchBlock('active');
60 }
61 }
62 $component = $component->withAdditionalOnLoadCode(function ($id) {
63 return '';
64 });
65 $id = $this->bindJavaScript($component);
66 $tpl->setVariable("ID", $id);
67
68 foreach ($component->getItems() as $subitem) {
69 if ($subitem instanceof Menu\Menu) {
70 $html = $default_renderer->render($subitem);
71 } else {
72 $html = $this->wrapMenuEntry($subitem, $default_renderer);
73 }
74 $tpl->setCurrentBlock('subitems');
75 $tpl->setVariable('SUBITEMS', $html);
76 $tpl->parseCurrentBlock();
77 }
78
79 return $tpl->get();
80 }
81
88 protected function wrapMenuEntry(
89 Component\Component $component,
90 RendererInterface $default_renderer
91 ) : string {
92 $tpl_name = "tpl.menuitem.html";
93 $tpl = $this->getTemplate($tpl_name, true, true);
94
95 $label = $default_renderer->render($component);
96 $tpl->setVariable('LABEL', $label);
97 return $tpl->get();
98 }
99
100
107 protected function maybeConvertLabelToShy($label) : Component\Clickable
108 {
109 if (is_string($label)) {
110 $label = $this->getUIFactory()->button()->shy($label, '');
111 }
112 return $label;
113 }
114
115
119 public function registerResources(\ILIAS\UI\Implementation\Render\ResourceRegistry $registry)
120 {
121 parent::registerResources($registry);
122 $registry->register('./src/UI/templates/js/Menu/drilldown.js');
123 }
127 protected function getComponentInterfaceName()
128 {
129 return array(
130 Menu\Menu::class
131 );
132 }
133}
An exception for terminatinating execution or to throw for unit testing.
renderMenu(Menu\Menu $component, RendererInterface $default_renderer)
Render a Menu.
Definition: Renderer.php:47
maybeConvertLabelToShy($label)
A string will be converted to a Shy Button, any Clickables will be returned as they are.
Definition: Renderer.php:107
wrapMenuEntry(Component\Component $component, RendererInterface $default_renderer)
Wrap an entry like Clickable or Divider to fit the menu-structure.
Definition: Renderer.php:88
registerResources(\ILIAS\UI\Implementation\Render\ResourceRegistry $registry)
Definition: Renderer.php:119
getComponentInterfaceName()
Get the name of the component-interface this renderer is supposed to render.ATTENTION: Fully qualifie...
Definition: Renderer.php:127
render(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:18
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
This describes a Drilldown Menu Control.
Definition: Drilldown.php:15
This describes a Menu Control.
Definition: Menu.php:14
This describes a Submenu, i.e.
Definition: Sub.php:15
An entity that renders components to a string output.
Definition: Renderer.php:15
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl