ILIAS  release_8 Revision v8.24
Renderer.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
24use ILIAS\UI\Renderer as RendererInterface;
28
30{
34 public function render(Component\Component $component, RendererInterface $default_renderer): string
35 {
36 $this->checkComponent($component);
37
41 $html = $this->renderMenu($component, $default_renderer);
42
43 if ($component instanceof Menu\Drilldown) {
44 $ui_factory = $this->getUIFactory();
45 $back_signal = $component->getBacklinkSignal();
46 $persistence_id = $component->getPersistenceId();
47 $glyph = $ui_factory->symbol()->glyph()->collapsehorizontal();
48 $btn = $ui_factory->button()->bulky($glyph, '', '#')
49 ->withOnClick($back_signal)
50 ->withAriaLabel($this->txt('back'));
51 $back_button_html = $default_renderer->render($btn);
52
53 $component = $component->withAdditionalOnLoadCode(
54 function ($id) use ($back_signal, $persistence_id) {
55 $params = "'$id', '$back_signal'";
56 if (is_null($persistence_id)) {
57 $params .= ", null";
58 } else {
59 $params .= ", '$persistence_id'";
60 }
61 return "il.UI.menu.drilldown.init($params);";
62 }
63 );
64 $id = $this->bindJavaScript($component);
65
66 $tpl_name = "tpl.drilldown.html";
67 $tpl = $this->getTemplate($tpl_name, true, true);
68 $tpl->setVariable("ID", $id);
69 $tpl->setVariable('TITLE', $component->getLabel());
70 $tpl->setVariable('BACKNAV', $back_button_html);
71 $tpl->setVariable('DRILLDOWN', $html);
72
73 return $tpl->get();
74 }
75
76 return $html;
77 }
78
82 protected function renderMenu(
83 Menu\Menu $component,
84 RendererInterface $default_renderer
85 ): string {
86 $tpl_menu = $this->getTemplate('tpl.menu.html', true, true);
87
88 $label = $component->getLabel();
89 if (!is_string($label)) {
90 $label = $default_renderer->render($label);
91 }
92 $tpl_menu->setVariable('LABEL', $label);
93
94 $html = '';
95 foreach ($component->getItems() as $item) {
96 $tpl_item = $this->getTemplate('tpl.menuitem.html', true, true);
97 $tpl_item->setVariable('ITEM', $default_renderer->render($item));
98 $html .= $tpl_item->get();
99 }
100 $tpl_menu->setVariable('ITEMS', $html);
101 return $tpl_menu->get();
102 }
103
107 public function registerResources(ResourceRegistry $registry): void
108 {
109 parent::registerResources($registry);
110 $registry->register('./src/UI/templates/js/Menu/dist/drilldown.js');
111 }
112
116 protected function getComponentInterfaceName(): array
117 {
118 return array(
119 Menu\Menu::class
120 );
121 }
122}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
registerResources(ResourceRegistry $registry)
Announce resources this renderer requires.
Definition: Renderer.php:107
renderMenu(Menu\Menu $component, RendererInterface $default_renderer)
Render a Menu.
Definition: Renderer.php:82
getComponentInterfaceName()
Get the name of the component-interface this renderer is supposed to render.ATTENTION: Fully qualifie...
Definition: Renderer.php:116
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.
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
return true
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.
register(string $name)
Add a dependency.
An entity that renders components to a string output.
Definition: Renderer.php:31
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Drilldown.php:21