ILIAS  release_7 Revision v7.30-3-g800a261c036
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
25 $html = $this->renderMenu($component, $default_renderer);
26
27 if ($component instanceof Menu\Drilldown) {
28 $tpl_name = "tpl.drilldown.html";
29 $tpl = $this->getTemplate($tpl_name, true, true);
30 $tpl->setVariable('DRILLDOWN', $html);
31
32 $component = $component->withAdditionalOnLoadCode(function ($id) {
33 return "il.UI.menu.drilldown.init('$id');";
34 });
35 $id = $this->bindJavaScript($component);
36 $tpl->setVariable("ID", $id);
37
38 return $tpl->get();
39 }
40
41 return $html;
42 }
43
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
57 $label = $this->maybeConvertLabelToShy($component->getLabel());
58 $tpl->setVariable('LABEL', $default_renderer->render($label));
59
60 if ($component instanceof Menu\Sub) {
61 if ($component->isInitiallyActive()) {
62 $tpl->touchBlock('active');
63 }
64 }
68 $component = $component->withAdditionalOnLoadCode(function ($id) {
69 return '';
70 });
71 $id = $this->bindJavaScript($component);
72 $tpl->setVariable("ID", $id);
73
74 foreach ($component->getItems() as $subitem) {
75 if ($subitem instanceof Menu\Menu) {
76 $html = $default_renderer->render($subitem);
77 } else {
78 $html = $this->wrapMenuEntry($subitem, $default_renderer);
79 }
80 $tpl->setCurrentBlock('subitems');
81 $tpl->setVariable('SUBITEMS', $html);
82 $tpl->parseCurrentBlock();
83 }
84
85 return $tpl->get();
86 }
87
91 protected function wrapMenuEntry(
92 Component\Component $component,
93 RendererInterface $default_renderer
94 ) : string {
95 $tpl_name = "tpl.menuitem.html";
96 $tpl = $this->getTemplate($tpl_name, true, true);
97
98 $label = $default_renderer->render($component);
99 $tpl->setVariable('LABEL', $label);
100 return $tpl->get();
101 }
102
103
108 protected function maybeConvertLabelToShy($label) : Component\Clickable
109 {
110 if (is_string($label)) {
111 $label = $this->getUIFactory()->button()->shy($label, '');
112 }
113 return $label;
114 }
115
116
120 public function registerResources(\ILIAS\UI\Implementation\Render\ResourceRegistry $registry)
121 {
122 parent::registerResources($registry);
123 $registry->register('./src/UI/templates/js/Menu/drilldown.js');
124 }
128 protected function getComponentInterfaceName()
129 {
130 return array(
131 Menu\Menu::class
132 );
133 }
134}
An exception for terminatinating execution or to throw for unit testing.
maybeConvertLabelToShy($label)
A string will be converted to a Shy Button, any Clickables will be returned as they are.
Definition: Renderer.php:108
wrapMenuEntry(Component\Component $component, RendererInterface $default_renderer)
Wrap an entry like Clickable or Divider to fit the menu-structure.
Definition: Renderer.php:91
registerResources(\ILIAS\UI\Implementation\Render\ResourceRegistry $registry)
Definition: Renderer.php:120
getComponentInterfaceName()
Get the name of the component-interface this renderer is supposed to render.ATTENTION: Fully qualifie...
Definition: Renderer.php:128
Level of Drilldown Control.
Definition: Sub.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.
A component is the most general form of an entity in the UI.
Definition: Component.php:14
render(Component $component, Renderer $default_renderer)
Render the component if possible and delegate additional rendering to the default_renderer.
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
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.