ILIAS  trunk Revision v11.0_alpha-2645-g16283d3b3f8
Renderer.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 use LogicException;
29 
31 {
35  public function render(Component\Component $component, RendererInterface $default_renderer): string
36  {
37  if ($component instanceof Component\Link\Standard) {
38  return $this->renderStandard($component);
39  }
40  if ($component instanceof Component\Link\Bulky) {
41  return $this->renderBulky($component, $default_renderer);
42  }
43  $this->cannotHandleComponent($component);
44  }
45 
46  protected function setStandardVars(
47  string $tpl_name,
48  Component\Link\Link $component
49  ): Template {
50  $tpl = $this->getTemplate($tpl_name, true, true);
51  $action = $component->getAction();
52  $label = $component->getLabel();
53  if ($component->getOpenInNewViewport()) {
54  $tpl->touchBlock("open_in_new_viewport");
55  }
56  if (null !== $component->getContentLanguage()) {
57  $tpl->setVariable("CONTENT_LANGUAGE", $component->getContentLanguage());
58  }
59  if (null !== $component->getLanguageOfReferencedResource()) {
60  $tpl->setVariable("HREF_LANGUAGE", $component->getLanguageOfReferencedResource());
61  }
62 
63  $rel_strings = [];
64  foreach ($component->getRelationshipsToReferencedResource() as $rel) {
65  $rel_strings[] = $rel->value;
66  }
67  if (!empty($rel_strings)) {
68  $tpl->setVariable("RELS", implode(' ', $rel_strings));
69  }
70 
71  $tpl->setVariable("LABEL", $label);
72  if($component->isDisabled()) {
73  $tpl->touchBlock("ariadisabled", $action);
74  } else {
75  $tpl->setVariable("HREF", $action);
76  }
77  return $tpl;
78  }
79 
80  protected function maybeRenderWithTooltip(Component\Link\Link $component, Template $tpl): string
81  {
82  $tooltip_embedding = $this->getTooltipRenderer()->maybeGetTooltipEmbedding(...$component->getHelpTopics());
83  if (! $tooltip_embedding) {
84  $id = $this->bindJavaScript($component);
85  $tpl->setVariable("ID", $id);
86  return $tpl->get();
87  }
88  $component = $component->withAdditionalOnLoadCode($tooltip_embedding[1]);
89  $tooltip_id = $this->createId();
90  $tpl->setCurrentBlock("with_aria_describedby");
91  $tpl->setVariable("ARIA_DESCRIBED_BY", $tooltip_id);
92  $tpl->parseCurrentBlock();
93  $id = $this->bindJavaScript($component);
94  $tpl->setVariable("ID", $id);
95  return $tooltip_embedding[0]($tooltip_id, $tpl->get());
96  }
97 
98  protected function renderStandard(
99  Component\Link\Standard $component
100  ): string {
101  $tpl_name = "tpl.standard.html";
102  $tpl = $this->setStandardVars($tpl_name, $component);
103  return $this->maybeRenderWithTooltip($component, $tpl);
104  }
105 
106  protected function renderBulky(
107  Component\Link\Bulky $component,
108  RendererInterface $default_renderer
109  ): string {
110  $tpl_name = "tpl.bulky.html";
111  $tpl = $this->setStandardVars($tpl_name, $component);
112 
113  $symbol = $component->getSymbol();
114  if($symbol !== null) {
115  if ($component->getLabel() !== '') {
116  $symbol = $symbol->withLabel('');
117  }
118  $tpl->setVariable("SYMBOL", $default_renderer->render($symbol));
119  }
120 
121  $aria_role = $component->getAriaRole();
122  if ($aria_role != null) {
123  $tpl->setCurrentBlock("with_aria_role");
124  $tpl->setVariable("ARIA_ROLE", $aria_role);
125  $tpl->parseCurrentBlock();
126  }
127  return $this->maybeRenderWithTooltip($component, $tpl);
128  }
129 }
get(?string $block=null)
Get the rendered template or a specific block.
setCurrentBlock(string $name)
Set the block to work on.
setVariable(string $name, $value)
Set a variable in the current block.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
cannotHandleComponent(Component $component)
This method MUST be called by derived component renderers, if.
parseCurrentBlock()
Parse the block that is currently worked on.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.