ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
TooltipRenderer.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
24 use ILIAS\UI\Help;
25 
31 {
32  public function __construct(
33  protected HelpTextRetriever $help_text_retriever,
34  protected $get_template
35  ) {
36  if (!is_callable($this->get_template)) {
37  throw new \InvalidArgumentException("\$get_template should be callable.");
38  }
39  }
40 
53  public function maybeGetTooltipEmbedding(Help\Topic ...$topics): ?array
54  {
55  if (count($topics) === 0) {
56  return null;
57  }
58 
59  $tooltips = $this->help_text_retriever->getHelpText(Help\Purpose::Tooltip(), ...$topics);
60  if (count($tooltips) === 0) {
61  return null;
62  }
63 
64  $get_template = $this->get_template;
65  $embed_html = static function (string $tooltip_id, string $component_html) use ($tooltips, $get_template): string {
66  $tpl = $get_template("components/ILIAS/UI/src/templates/default/tpl.tooltip.html", true, true);
67  $tpl->setVariable("ELEMENT", $component_html);
68  $tpl->setVariable("TOOLTIP_ID", $tooltip_id);
69 
70  foreach ($tooltips as $tooltip) {
71  $tpl->setCurrentBlock("tooltip");
72  $tpl->setVariable("TOOLTIP", $tooltip);
73  $tpl->parseCurrentBlock();
74  }
75 
76  return $tpl->get();
77  };
78 
79  $embed_js = static function ($id) {
80  return "new il.UI.core.Tooltip(document.getElementById('$id'));";
81  };
82 
83  return [$embed_html, $embed_js];
84  }
85 }
This is just a class that marks a string as a help topic.
Definition: Topic.php:26
This describes a facility that the UI framework can use to retrieve some help text.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class is supposed to unify rendering of tooltips over all components and should also be usable b...
__construct(protected HelpTextRetriever $help_text_retriever, protected $get_template)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
maybeGetTooltipEmbedding(Help\Topic ... $topics)
This will provide functions that can be used to embed a components html into some html required for t...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Purpose.php:21