ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Renderer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\UI\Renderer as RendererInterface;
29use iljQueryUtil;
30use LogicException;
31
33{
34 public const string COOKIE_NAME_SLATES_ENGAGED = 'il_mb_slates';
35
39 public function render(Component\Component $component, RendererInterface $default_renderer): string
40 {
41 if ($component instanceof Component\Layout\Page\Standard) {
42 return $this->renderStandardPage($component, $default_renderer);
43 }
44
45 $this->cannotHandleComponent($component);
46 }
47
48 protected function renderStandardPage(
49 Component\Layout\Page\Standard $component,
50 RendererInterface $default_renderer
51 ): string {
52 $tpl = $this->getTemplate("tpl.standardpage.html", true, true);
53
54 $tpl->setVariable('FAVICON_PATH', $component->getFaviconPath());
55
56 $id = $this->bindJavaScript($component);
57 $tpl->setVariable("ID", $id);
58
59 if ($component->hasOverlay()) {
60 $tpl->setVariable('OVERLAY', $default_renderer->render($component->getOverlay()));
61 }
62 if ($component->hasMetabar()) {
63 $tpl->setVariable('METABAR', $default_renderer->render($component->getMetabar()));
64 }
65 if ($component->hasMainbar()) {
66 $tpl->setVariable('MAINBAR', $default_renderer->render($component->getMainbar()));
67 // There is a roadmap entry for this.
68 $slates_cookie = $_COOKIE[self::COOKIE_NAME_SLATES_ENGAGED] ?? '';
69 if ($slates_cookie && json_decode($slates_cookie, true)['engaged']) {
70 $tpl->touchBlock('slates_engaged');
71 }
72 }
73 if ($component->hasModeInfo()) {
74 $tpl->setVariable('MODEINFO', $default_renderer->render($component->getModeInfo()));
75 }
76 if ($component->hasSystemInfos()) {
77 $tpl->setVariable('SYSTEMINFOS', $default_renderer->render($component->getSystemInfos()));
78 }
79
80 $breadcrumbs = $component->getBreadcrumbs();
81 if ($breadcrumbs && $breadcrumbs->getItems()) {
82 $tpl->setVariable('BREADCRUMBS', $default_renderer->render($breadcrumbs));
83
84 $dropdown = $this->convertBreadcrumbsToDropdownLocator($breadcrumbs);
85 $tpl->setVariable('HEADER_BREADCRUMBS', $default_renderer->render($dropdown));
86 }
87 if ($component->hasLogo()) {
88 $tpl->setVariable('LOGO', $default_renderer->render($component->getLogo()));
89 }
90 if ($component->hasResponsiveLogo()) {
91 $tpl->setVariable('RESPONSIVE_LOGO', $default_renderer->render($component->getResponsiveLogo()));
92 } elseif ($component->hasLogo()) {
93 $tpl->setVariable('RESPONSIVE_LOGO', $default_renderer->render($component->getLogo()));
94 }
95
96 $tpl->setVariable("TITLE", $component->getTitle());
97 $tpl->setVariable("SHORT_TITLE", $component->getShortTitle());
98 $tpl->setVariable("VIEW_TITLE", $component->getViewTitle());
99 $tpl->setVariable("LANGUAGE", $this->getLangKey());
100 $tpl->setVariable("TEXT_DIRECTION", $component->getTextDirection());
101 $tpl->setVariable('CONTENT', $default_renderer->render($component->getContent()));
102
103 if ($component->hasFooter()) {
104 $tpl->setVariable('FOOTER', $default_renderer->render($component->getFooter()));
105 }
106
107 if ($component->getWithHeaders()) {
108 $tpl = $this->setHeaderVars($tpl, $component->getIsUIDemo());
109 }
110
111 $tpl->setVariable('META_DATA', $this->getDataFactory()->htmlMetadata()->collection(
112 $component->getMetaData()
113 )->toHtml());
114
115 return $tpl->get();
116 }
117
120 ): Component\Dropdown\Dropdown {
121 $f = $this->getUIFactory();
122 $buttons = [];
123 $items = array_reverse($breadcrumbs->getItems());
124 $current = array_shift($items);
125 foreach ($items as $item) {
126 $button = $f->button()->shy(
127 $item->getLabel(),
128 $item->getAction()
129 );
130 $buttons[] = $button;
131 }
132 return $f->dropdown()->standard($buttons)->withLabel($current->getLabel());
133 }
134
141 protected function setHeaderVars(Template $tpl, bool $for_ui_demo = false): Template
142 {
143 global $DIC;
144 $il_tpl = $DIC["tpl"] ?? null;
145
146 $js_files = [];
147 $js_inline = [];
148 $css_files = [];
149 $css_inline = [];
150
151 if ($il_tpl instanceof ilGlobalPageTemplate) {
152 $layout = $DIC->globalScreen()->layout();
153 foreach ($layout->meta()->getJs()->getItemsInOrderOfDelivery() as $js) {
154 $js_files[] = $js->getContent();
155 }
156 foreach ($layout->meta()->getCss()->getItemsInOrderOfDelivery() as $css) {
157 $css_files[] = ['file' => $css->getContent(), 'media' => $css->getMedia()];
158 }
159 foreach ($layout->meta()->getInlineCss()->getItemsInOrderOfDelivery() as $inline_css) {
160 $css_inline[] = $inline_css->getContent();
161 }
162 foreach ($layout->meta()->getOnloadCode()->getItemsInOrderOfDelivery() as $on_load_code) {
163 $js_inline[] = $on_load_code->getContent();
164 }
165 }
166
167 if ($for_ui_demo) {
168 $additional_js_files = [
170 'assets/js/Basic.js',
171 './assets/js/jquery.js',
172 './assets/js/jquery-migrate.min.js',
173 ];
174
175 array_unshift($js_files, ...$additional_js_files);
176
177 $css_files[] = ['file' => './assets/css/delos.css'];
178 }
179
180 foreach ($js_files as $js_file) {
181 $tpl->setCurrentBlock("js_file");
182 $tpl->setVariable("JS_FILE", $js_file);
183 $tpl->parseCurrentBlock();
184 }
185 foreach ($css_files as $css_file) {
186 $tpl->setCurrentBlock("css_file");
187 $tpl->setVariable("CSS_FILE", $css_file['file']);
188 $tpl->parseCurrentBlock();
189 }
190
191 $tpl->setVariable("CSS_INLINE", implode(PHP_EOL, $css_inline));
192 $tpl->setVariable("OLCODE", implode(PHP_EOL, $js_inline));
193
194 return $tpl;
195 }
196
200 public function registerResources(ResourceRegistry $registry): void
201 {
202 parent::registerResources($registry);
203 $registry->register('assets/js/stdpage.js');
204 }
205}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
setHeaderVars(Template $tpl, bool $for_ui_demo=false)
When rendering the whole page, all resources must be included.
Definition: Renderer.php:141
convertBreadcrumbsToDropdownLocator(Component\Breadcrumbs\Breadcrumbs $breadcrumbs)
Definition: Renderer.php:118
render(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:39
renderStandardPage(Component\Layout\Page\Standard $component, RendererInterface $default_renderer)
Definition: Renderer.php:48
registerResources(ResourceRegistry $registry)
Announce resources this renderer requires.
Definition: Renderer.php:200
cannotHandleComponent(Component $component)
This method MUST be called by derived component renderers, if.
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
return true
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getLocaljQueryPath()
This describes the Page.
Definition: Page.php:31
Registry for resources required by rendered output like Javascript or CSS.
register(string $name)
Add a dependency.
Interface to templating as it is used in the UI framework.
Definition: Template.php:29
setVariable(string $name, $value)
Set a variable in the current block.
setCurrentBlock(string $name)
Set the block to work on.
parseCurrentBlock()
Parse the block that is currently worked on.
An entity that renders components to a string output.
Definition: Renderer.php:31
global $DIC
Definition: shib_login.php:26
$_COOKIE[session_name()]
Definition: xapitoken.php:54