ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
Renderer.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types=1);
3 
4 /* Copyright (c) 2019 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
5 
7 
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 }
Class Factory.
render(Component\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:18
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
checkComponent(Component $component)
Check if a given component fits this renderer and throw if that is not the case. ...
Class ChatMainBarProvider .
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
This describes a Menu Control.
Definition: Menu.php:13
This describes a Submenu, i.e.
Definition: Sub.php:14
registerResources(\ILIAS\UI\Implementation\Render\ResourceRegistry $registry)
Definition: Renderer.php:119
This describes a Drilldown Menu Control.
Definition: Drilldown.php:14
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.