19declare(strict_types=1);
54 if ($component instanceof
MainBar) {
55 return $this->renderMainbar($component, $default_renderer);
57 if ($component instanceof
MetaBar) {
58 return $this->renderMetabar($component, $default_renderer);
60 if ($component instanceof
Footer) {
61 return $this->
renderFooter($component, $default_renderer);
63 if ($component instanceof
ModeInfo) {
74 if (!$slate instanceof
Slate && !$slate instanceof
MainBar) {
78 ->withMainBarTreePosition($pos)
80 function ($num, $slate, $is_tool =
false) use ($pos) {
93 UITemplateWrapper $tpl,
94 RendererInterface $default_renderer
96 $hidden = $component->getInitiallyHiddenToolIds();
99 $is_removeable = array_key_exists($entry_id, $close_buttons);
100 $is_hidden = in_array($entry_id, $hidden);
102 if ($is_removeable) {
103 $trigger_signal = $component->getTriggerSignal($mb_id, $component::ENTRY_ACTION_REMOVE);
104 $this->trigger_signals[] = $trigger_signal;
105 $btn_removetool = $close_buttons[$entry_id]
106 ->withAdditionalOnloadCode(
107 fn(
$id) =>
"il.UI.maincontrols.mainbar.addPartIdAndEntry('$mb_id', 'remover', '$id', true);"
109 ->withOnClick($trigger_signal);
111 $tpl->setCurrentBlock(
"tool_removal");
112 $tpl->setVariable(
"REMOVE_TOOL", $default_renderer->render($btn_removetool));
113 $tpl->parseCurrentBlock();
116 $is_removeable = $is_removeable ?
'true' :
'false';
117 $is_hidden = $is_hidden ?
'true' :
'false';
118 return "il.UI.maincontrols.mainbar.addToolEntry('$mb_id', $is_removeable, $is_hidden, '$entry_id');";
125 UITemplateWrapper $tpl,
126 RendererInterface $default_renderer
128 $f = $this->getUIFactory();
129 foreach ($entries as $k => $entry) {
134 if ($entry instanceof
Slate) {
136 $mb_id = $entry->getMainBarTreePosition();
137 $is_tool = $block === static::BLOCK_MAINBAR_TOOLS;
139 $js = $this->renderToolEntry($k, $mb_id, $component, $tpl, $default_renderer);
142 $trigger_signal = $component->getTriggerSignal($mb_id, $component::ENTRY_ACTION_TRIGGER);
143 $this->trigger_signals[] = $trigger_signal;
144 $button =
$f->button()->bulky($entry->getSymbol(), $entry->getName(),
'#')
145 ->withOnClick($trigger_signal)
146 ->withHelpTopics(...$entry->getHelpTopics());
149 $pos = array_search($k, array_keys($entries));
150 $mb_id =
'0:' . $pos;
154 $button = $button->withAdditionalOnLoadCode(
155 function (
$id) use ($js, $mb_id, $k, $is_tool):
string {
156 $add_as_tool = $is_tool ?
'true' :
'false';
158 il.UI.maincontrols.mainbar.addPartIdAndEntry('$mb_id', 'triggerer', '$id', $add_as_tool);
159 il.UI.maincontrols.mainbar.addMapping('$k','$mb_id');
163 )->withAriaRole(IBulky::MENUITEM);
165 $tpl->setCurrentBlock($block);
166 $tpl->setVariable(
"BUTTON", $default_renderer->render($button));
167 $tpl->parseCurrentBlock();
170 if (!$entry instanceof LegacySlate) {
171 $entry = $entry->withAriaRole(ISlate::MENU);
174 $tpl->setCurrentBlock(
"slate_item");
175 $tpl->setVariable(
"SLATE", $default_renderer->render($entry));
176 $tpl->parseCurrentBlock();
181 protected function renderMainbar(MainBar $component, RendererInterface $default_renderer): string
183 $f = $this->getUIFactory();
184 $tpl = $this->getTemplate(
"tpl.mainbar.html",
true,
true);
186 $tpl->setVariable(
"ARIA_LABEL", $this->txt(
'mainbar_aria_label'));
187 $more_btn_label = $this->txt(
'mainbar_more_label');
191 $more_slate =
$f->mainControls()->slate()->combined(
193 $f->symbol()->glyph()->more()
195 $more_slate = $more_slate->withAriaRole(ISlate::MENU);
196 $component = $component->withAdditionalEntry(
200 $component = $this->calculateMainBarTreePosition(
"0", $component);
203 static::BLOCK_MAINBAR_ENTRIES => $component->getEntries(),
204 static::BLOCK_MAINBAR_TOOLS => $component->getToolEntries()
207 foreach ($mb_entries as $block => $entries) {
208 $this->renderMainbarEntry(
218 if (count($component->getToolEntries()) > 0) {
219 $btn_tools = $component->getToolsButton()
220 ->withOnClick($component->getToggleToolsSignal());
222 $tpl->setCurrentBlock(
"tools_trigger");
223 $tpl->setVariable(
"BUTTON", $default_renderer->render($btn_tools));
224 $tpl->parseCurrentBlock();
228 $btn_disengage =
$f->button()->bulky(
$f->symbol()->glyph()->collapseHorizontal(
"#"), $this->txt(
'close'),
"")
229 ->withOnClick($component->getDisengageAllSignal());
230 $tpl->setVariable(
"CLOSE_SLATES", $default_renderer->render($btn_disengage));
233 $id = $this->bindMainbarJS($component);
234 $tpl->setVariable(
'ID',
$id);
239 protected function renderMetabar(MetaBar $component, RendererInterface $default_renderer): string
241 $f = $this->getUIFactory();
242 $tpl = $this->getTemplate(
"tpl.metabar.html",
true,
true);
245 'entry' => $component->getEntryClickSignal(),
246 'close_slates' => $component->getDisengageAllSignal()
248 $entries = $component->getEntries();
250 $more_label = $this->txt(
'show_more');
251 $more_symbol =
$f->symbol()->glyph()->disclosure()
252 ->withCounter(
$f->counter()->novelty(0))
253 ->withCounter(
$f->counter()->status(0));
257 $more_slate =
$f->mainControls()->slate()->combined($more_label, $more_symbol);
258 $more_slate = $more_slate->withAriaRole(ISlate::MENU);
259 $entries[] = $more_slate;
261 $this->renderTriggerButtonsAndSlates(
265 static::BLOCK_METABAR_ENTRIES,
270 $component = $component->withOnLoadCode(
271 function (
$id) use ($signals) {
272 $entry_signal = $signals[
'entry'];
273 $close_slates_signal = $signals[
'close_slates'];
275 il.UI.maincontrols.metabar.init('$id');
276 il.UI.maincontrols.metabar.get('$id').registerSignals(
278 '$close_slates_signal',
280 il.UI.maincontrols.metabar.get('$id').init();
281 window.addEventListener(
283 ()=>{il.UI.maincontrols.metabar.get('$id').init()}
288 $tpl->setVariable(
'ARIA_LABEL', $this->txt(
'metabar_aria_label'));
290 $id = $this->bindJavaScript($component);
291 $tpl->setVariable(
'ID',
$id);
297 $f = $this->getUIFactory();
298 $tpl = $this->getTemplate(
"tpl.mode_info.html",
true,
true);
299 $tpl->setVariable(
'MODE_TITLE', $component->
getModeTitle());
302 $action = $base_URI .
'?' . $query;
303 $close =
$f->button()->shy(
306 )->withSymbol(
$f->symbol()->glyph()->close());
307 $tpl->setVariable(
'CLOSE_GLYPH', $default_renderer->render($close));
314 RendererInterface $default_renderer
316 $tpl = $this->getTemplate(
"tpl.system_info.html",
true,
true);
317 $tpl->setVariable(
'HEADLINE', $component->getHeadLine());
318 $tpl->setVariable(
'BODY', $component->getInformationText());
319 $tpl->setVariable(
'DENOTATION', $component->getDenotation());
320 switch ($component->getDenotation()) {
321 case Component\MainControls\SystemInfo::DENOTATION_NEUTRAL:
322 case Component\MainControls\SystemInfo::DENOTATION_IMPORTANT:
323 $tpl->setVariable(
'ROLE',
'role="status"');
324 $tpl->setVariable(
'LIVE',
'aria-live="polite"');
326 case Component\MainControls\SystemInfo::DENOTATION_BREAKING:
327 $tpl->setVariable(
'ROLE',
'role="alert"');
330 if ($component->isDismissable()) {
331 $signal = $component->getCloseSignal();
332 $close = $this->getUIFactory()->button()->shy(
'',
'')->withOnClick($signal)->withSymbol($this->getUIFactory()->
symbol()->glyph()->
close());
333 $tpl->setVariable(
'CLOSE_BUTTON', $default_renderer->render($close));
334 $tpl->setVariable(
'CLOSE_URI', (
string) $component->getDismissAction());
335 $component = $component->withAdditionalOnLoadCode(fn(
$id) =>
"$(document).on('$signal', function() { il.UI.maincontrols.system_info.close('$id'); });");
338 $more = $this->getUIFactory()->button()->shy(
'',
'')
339 ->withSymbol($this->getUIFactory()->
symbol()->glyph()->
more());
340 $tpl->setVariable(
'MORE_BUTTON', $default_renderer->render($more));
342 $component = $component->withAdditionalOnLoadCode(fn(
$id) =>
"il.UI.maincontrols.system_info.init('$id')");
344 $id = $this->bindJavaScript($component);
345 $tpl->setVariable(
'ID',
$id);
346 $tpl->setVariable(
'ID_HEADLINE',
$id .
"_headline");
347 $tpl->setVariable(
'ID_DESCRIPTION',
$id .
"_description");
354 UITemplateWrapper $tpl,
355 RendererInterface $default_renderer,
359 ?
string $active =
null
361 foreach ($entries as
$id => $entry) {
365 if ($entry instanceof
Slate) {
366 $f = $this->getUIFactory();
367 $secondary_signal = $entry->getToggleSignal();
368 $clickable =
$f->button()->bulky($entry->getSymbol(), $entry->getName(),
'#')
370 ->withOnClick($entry_signal)
371 ->appendOnClick($secondary_signal)
372 ->withAriaRole(IBulky::MENUITEM)
373 ->withHelpTopics(...$entry->getHelpTopics());
376 } elseif ($entry instanceof IBulky) {
378 $clickable = $clickable->withAriaRole(IBulky::MENUITEM);
384 $clickable_html = $default_renderer->render($clickable);
387 $tpl->setCurrentBlock(
"slate_item");
388 $tpl->setVariable(
"SLATE", $default_renderer->render($slate));
389 $tpl->parseCurrentBlock();
392 $tpl->setCurrentBlock($use_block);
393 $tpl->setVariable(
"BUTTON", $clickable_html);
394 $tpl->parseCurrentBlock();
400 $trigger_signals = $this->trigger_signals;
402 $this->toJS(
'close');
404 $inititally_active = $component->
getActive();
407 function (
$id) use ($component, $trigger_signals, $inititally_active):
string {
411 $js =
"il.UI.maincontrols.mainbar.addTriggerSignal('$disengage_all_signal');";
412 $js .=
"il.UI.maincontrols.mainbar.addTriggerSignal('$tools_toggle_signal');";
414 foreach ($trigger_signals as $signal) {
415 $js .=
"il.UI.maincontrols.mainbar.addTriggerSignal('$signal');";
419 $signal = $component->getEngageToolSignal($k);
420 $js .=
"il.UI.maincontrols.mainbar.addTriggerSignal('$signal');";
424 window.addEventListener('resize', il.UI.maincontrols.mainbar.adjustToScreenSize);
425 il.UI.maincontrols.mainbar.init('$inititally_active');
431 return $this->bindJavaScript($component);
436 if (!$this->isFooterVisible($component)) {
440 $template = $this->getTemplate(
"tpl.footer.html",
true,
true);
443 $permanent_url = $component->getPermanentURL();
444 if (
null !== $permanent_url) {
445 $template->setCurrentBlock(
'with_additional_item');
446 $template->setVariable(
'ITEM_CONTENT', $this->permanentLink((
string) $permanent_url, $default_renderer));
447 $template->parseCurrentBlock();
448 $this->parseFooterSection($template,
'permanent-link', $this->txt(
'footer_permanent_link'));
452 $additional_link_groups = $component->getAdditionalLinkGroups();
453 if ([] !== $additional_link_groups) {
455 foreach ($additional_link_groups as [$title, $actions]) {
456 $link_groups[] = [$this->getUIFactory()->listing()->unordered($actions), $title];
459 $this->parseAdditionalFooterSectionItems(
463 $this->txt(
'footer_link_groups'),
469 $additional_links = $component->getAdditionalLinks();
470 if ([] !== $additional_links) {
471 $links = array_map(
static fn($link) => [$link,
null], $additional_links);
472 $this->parseAdditionalFooterSectionItems(
476 $this->txt(
'footer_links'),
482 $additional_icons = $component->getAdditionalIcons();
483 if ([] !== $additional_icons) {
485 foreach ($additional_icons as [$icon, $action]) {
486 if (
null !== $action) {
487 if ($action instanceof
URI) {
488 $action = (string) $action;
490 $icons[] = $this->getUIFactory()->button()->shy(
'', $action)->withSymbol($icon);
496 $this->parseAdditionalFooterSectionIcons(
500 $this->txt(
'footer_icons'),
506 $additional_texts = $component->getAdditionalTexts();
507 if ([] !== $additional_texts) {
508 $texts = array_map(
static fn(
$text) => [
$text,
null], $additional_texts);
509 $this->parseAdditionalFooterSectionItems(
513 $this->txt(
'footer_texts'),
520 return $template->get() . $default_renderer->render($component->getModals());
528 RendererInterface $default_renderer,
529 string $section_type,
530 string $section_label,
531 array $section_items = [],
533 foreach ($section_items as [$content, $title]) {
535 if (
null !== $title) {
536 $template->
setVariable(
'ITEM_TITLE', $this->convertSpecialCharacters($title));
539 $content = $default_renderer->render($content);
541 $content = $this->convertSpecialCharacters($content);
547 $this->parseFooterSection($template, $section_type, $section_label);
555 RendererInterface $default_renderer,
556 string $section_type,
557 string $section_label,
558 array $section_icons = [],
560 foreach ($section_icons as $icon) {
562 $template->
setVariable(
'ICON', $default_renderer->render($icon));
566 $this->parseFooterSection($template, $section_type, $section_label);
571 string $section_type,
572 string $section_label,
574 $template->setCurrentBlock(
'with_additional_section');
575 $template->
setVariable(
'SECTION_TYPE', $section_type);
576 $template->
setVariable(
'SECTION_LABEL', $section_label);
582 return $component->getPermanentURL() !==
null
583 || !empty($component->getAdditionalLinkGroups())
584 || !empty($component->getAdditionalLinks())
585 || !empty($component->getAdditionalIcons())
586 || !empty($component->getAdditionalTexts());
594 parent::registerResources($registry);
595 $registry->
register(
'assets/js/mainbar.js');
596 $registry->
register(
'assets/js/maincontrols.min.js');
597 $registry->
register(
'assets/js/GS.js');
598 $registry->
register(
'assets/js/system_info.js');
599 $registry->
register(
'assets/js/footer.min.js');
604 $template = $this->getTemplate(
"tpl.permanent-link.html",
true,
true);
606 $code =
function (
string $id) use ($permanent_url):
string {
607 $id = $this->jsonEncode(
$id);
608 $perm_url = $this->jsonEncode((
string) $permanent_url);
610 return "document.getElementById($id).addEventListener('click', e => il.Footer.permalink.copyText($perm_url)
611 .then(() => il.Footer.permalink.showTooltip(e.target.nextElementSibling, 5000)));";
613 $button = $this->getUIFactory()->button()->standard($this->txt(
'copy_perma_link'),
'')->withAdditionalOnLoadCode($code);
616 $template->
setVariable(
'PERMANENT_TOOLTIP', $this->txt(
'perma_link_copied'));
618 return $template->
get();
623 return json_encode($value, JSON_HEX_QUOT | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_THROW_ON_ERROR);
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
The scope of this class is split ilias-conform URI's into components.
renderSystemInfo(Component\MainControls\SystemInfo $component, RendererInterface $default_renderer)
renderToolEntry(string $entry_id, string $mb_id, MainBar $component, UITemplateWrapper $tpl, RendererInterface $default_renderer)
parseAdditionalFooterSectionItems(Template $template, RendererInterface $default_renderer, string $section_type, string $section_label, array $section_items=[],)
const BLOCK_METABAR_ENTRIES
renderModeInfo(ModeInfo $component, RendererInterface $default_renderer)
renderTriggerButtonsAndSlates(UITemplateWrapper $tpl, RendererInterface $default_renderer, Signal $entry_signal, string $block, array $entries, ?string $active=null)
const BLOCK_MAINBAR_TOOLS
renderFooter(I\Footer $component, RendererInterface $default_renderer)
bindMainbarJS(MainBar $component)
parseFooterSection(Template $template, string $section_type, string $section_label,)
calculateMainBarTreePosition($pos, $slate)
renderMainbarEntry(array $entries, string $block, MainBar $component, UITemplateWrapper $tpl, RendererInterface $default_renderer)
parseAdditionalFooterSectionIcons(Template $template, RendererInterface $default_renderer, string $section_type, string $section_label, array $section_icons=[],)
registerResources(ResourceRegistry $registry)
Announce resources this renderer requires.
render(Component\Component $component, RendererInterface $default_renderer)
permanentLink(string $permanent_url, RendererInterface $renderer)
isFooterVisible(I\Footer $component)
const BLOCK_MAINBAR_ENTRIES
Base class for all component renderers.
cannotHandleComponent(Component $component)
This method MUST be called by derived component renderers, if.
withOnLoadCode(Closure $binder)
This describes the MainBar.
getCloseButtons()
Buttons to close tools; maybe configure with callback.
getToggleToolsSignal()
Signal to toggle the tools-section.
getDisengageAllSignal()
This signal disengages all slates when triggered.
This describes the MetaBar.
This describes the Legacy-Slate.
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.
setVariable(string $name, $value)
Set a variable in the current block.
get(?string $block=null)
Get the rendered template or a specific 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.