ILIAS  release_7 Revision v7.30-3-g800a261c036
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 
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 }
Class Factory.
checkComponent(Component $component)
Check if a given component fits this renderer and throw if that is not the case. ...
Class ChatMainBarProvider .
Level of Drilldown Control.
Definition: Sub.php:16
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
render(Component $component, Renderer $default_renderer)
Render the component if possible and delegate additional rendering to the default_renderer.
registerResources(\ILIAS\UI\Implementation\Render\ResourceRegistry $registry)
Definition: Renderer.php:120
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
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.