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;
27use LogicException;
28
30{
34 public function render(C\Component $component, RendererInterface $default_renderer): string
35 {
36 if ($component instanceof C\Panel\Secondary\Listing) {
37 return $this->renderListing($component, $default_renderer);
38 } elseif ($component instanceof C\Panel\Secondary\Legacy) {
39 return $this->renderLegacy($component, $default_renderer);
40 }
41 $this->cannotHandleComponent($component);
42 }
43
44 protected function renderListing(C\Panel\Secondary\Listing $component, RendererInterface $default_renderer): string
45 {
46 $tpl = $this->getTemplate("tpl.secondary.html", true, true);
47
48 $tpl = $this->parseHeader($component, $default_renderer, $tpl);
49
50 foreach ($component->getItemGroups() as $group) {
51 if ($group instanceof C\Item\Group) {
52 $tpl->setCurrentBlock("group");
53 $tpl->setVariable("ITEM_GROUP", $default_renderer->render($group));
54 $tpl->parseCurrentBlock();
55 }
56 }
57
58 $tpl = $this->parseFooter($component, $default_renderer, $tpl);
59
60 return $tpl->get();
61 }
62
63 protected function renderLegacy(C\Panel\Secondary\Legacy $component, RendererInterface $default_renderer): string
64 {
65 $tpl = $this->getTemplate("tpl.secondary.html", true, true);
66
67 $tpl = $this->parseHeader($component, $default_renderer, $tpl);
68
69 $tpl->setCurrentBlock("legacy");
70 $tpl->setVariable("BODY_LEGACY", $default_renderer->render($component->getLegacyComponent()));
71 $tpl->parseCurrentBlock();
72
73 $tpl = $this->parseFooter($component, $default_renderer, $tpl);
74
75 return $tpl->get();
76 }
77
78 protected function parseHeader(
79 C\Panel\Secondary\Secondary $component,
80 RendererInterface $default_renderer,
81 Template $tpl
82 ): Template {
83 $title = $component->getTitle();
84 $actions = $component->getActions();
85 $view_controls = $component->getViewControls();
86
87 if ($title != "" || $actions || $view_controls) {
88 $tpl->setVariable("TITLE", $title);
89 if ($actions) {
90 $tpl->setVariable("ACTIONS", $default_renderer->render($actions));
91 }
92 if ($view_controls) {
93 foreach ($view_controls as $view_control) {
94 $tpl->setCurrentBlock("view_controls");
95 $tpl->setVariable("VIEW_CONTROL", $default_renderer->render($view_control));
96 $tpl->parseCurrentBlock();
97 }
98 }
99 $tpl->setCurrentBlock("heading");
100 $tpl->parseCurrentBlock();
101 }
102 return $tpl;
103 }
104
105 protected function parseFooter(
106 C\Panel\Secondary\Secondary $component,
107 RendererInterface $default_renderer,
108 Template $tpl
109 ): Template {
110 $footer = $component->getFooter();
111
112 if ($footer) {
113 $tpl->setCurrentBlock("footer");
114 $tpl->setVariable("FOOTER", $default_renderer->render($footer));
115 $tpl->parseCurrentBlock();
116 }
117 return $tpl;
118 }
119}
parseFooter(C\Panel\Secondary\Secondary $component, RendererInterface $default_renderer, Template $tpl)
Definition: Renderer.php:105
renderLegacy(C\Panel\Secondary\Legacy $component, RendererInterface $default_renderer)
Definition: Renderer.php:63
render(C\Component $component, RendererInterface $default_renderer)
Definition: Renderer.php:34
renderListing(C\Panel\Secondary\Listing $component, RendererInterface $default_renderer)
Definition: Renderer.php:44
parseHeader(C\Panel\Secondary\Secondary $component, RendererInterface $default_renderer, Template $tpl)
Definition: Renderer.php:78
cannotHandleComponent(Component $component)
This method MUST be called by derived component renderers, if.
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
Interface to templating as it is used in the UI framework.
Definition: Template.php:29
An entity that renders components to a string output.
Definition: Renderer.php:31