ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
Renderer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\UI\Renderer as RendererInterface;
30
32{
36 public function render(Component\Component $component, RendererInterface $default_renderer): string
37 {
38 if (!$component instanceof Component\Card\Card) {
39 $this->cannotHandleComponent($component);
40 }
41
43 $component = $this->addTriggererOnLoadCode($component);
44
45 $tpl = $this->getTemplate("tpl.card.html", true, true);
46
47 $title = $component->getTitle();
48 if ($title instanceof Shy) {
49 $image_alt = $title->getLabel();
50 $title = $default_renderer->render($title);
51 } else {
52 $image_alt = $title;
53 }
54
55 if ($component->isHighlighted()) {
56 $tpl->touchBlock("highlight");
57 } else {
58 $tpl->touchBlock("no_highlight");
59 }
60
61 $id = $this->bindJavaScript($component);
62 if (!$id) {
63 $id = $this->createId();
64 }
65 if (!empty($component->getTitleAction())) {
66 if (is_string($component->getTitleAction())) {
67 $tpl->setCurrentBlock("title_action_begin");
68 $tpl->setVariable("HREF", $component->getTitleAction());
69 $tpl->setVariable("ID", $id);
70 $tpl->parseCurrentBlock();
71 } elseif ($title instanceof Shy) {
72 $title = $default_renderer->render($title);
73 }
74 if (is_array($component->getTitleAction())) {
75 $tpl->setCurrentBlock("title_action_begin");
76 $tpl->setVariable("ID", $id);
77 $tpl->parseCurrentBlock();
78 }
79 }
80
81 $tpl->setVariable("TITLE", $title);
82
83 if ($component->getImage()) {
84 $tpl->setVariable("IMAGE", $default_renderer->render(
85 $component->getImage()->withAlt($this->txt("open") . " " . strip_tags($image_alt))
86 ));
87 }
88
89 if (!empty($component->getTitleAction())) {
90 $tpl->touchBlock("title_action_end");
91 }
92
93 if (is_array($component->getSections())) {
94 foreach ($component->getSections() as $section) {
95 $tpl->setCurrentBlock("section");
96 $tpl->setVariable("SECTION", $default_renderer->render($section));
97 $tpl->parseCurrentBlock();
98 }
99 }
100
101 if ($component instanceof Component\Card\RepositoryObject) {
102 $tpl->setCurrentBlock("action");
103
104 $obj_icon = $component->getObjectIcon();
105 if ($obj_icon !== null) {
106 $tpl->setVariable("OBJECT_ICON", $default_renderer->render($obj_icon));
107 }
108
109 $progress = $component->getProgress();
110 if ($progress !== null) {
111 $tpl->setVariable("PROGRESS_STATUS", $default_renderer->render($progress));
112 }
113
114 $certificate = $component->getCertificateIcon();
115 if ($certificate !== null) {
116 $certificate_icon = new StandardIcon("cert", "Certificate", "medium", false);
117 $tpl->setVariable("PROGRESS_STATUS", $default_renderer->render($certificate_icon));
118 }
119
120 $dropdown = $component->getActions();
121 if ($dropdown !== null) {
122 $tpl->setVariable("DROPDOWN", $default_renderer->render($dropdown));
123 }
124
125 $tpl->parseCurrentBlock();
126 }
127
128 return $tpl->get();
129 }
130}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This implements commonalities between standard and primary buttons.
Definition: Button.php:35
cannotHandleComponent(Component $component)
This method MUST be called by derived component renderers, if.
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.
addTriggererOnLoadCode(Triggerer $triggerer)
Add onload-code for triggerer.
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
render(Component $component, Renderer $default_renderer)
Render the component if possible and delegate additional rendering to the default_renderer.
An entity that renders components to a string output.
Definition: Renderer.php:31