ILIAS  trunk Revision v11.0_alpha-1811-gd2d5443e411
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ILIAS\UI\Implementation\Render\TooltipRenderer Class Reference

This class is supposed to unify rendering of tooltips over all components and should also be usable by legacy UI components. More...

+ Collaboration diagram for ILIAS\UI\Implementation\Render\TooltipRenderer:

Public Member Functions

 __construct (protected HelpTextRetriever $help_text_retriever, protected $get_template)
 
 maybeGetTooltipEmbedding (Help\Topic ... $topics)
 This will provide functions that can be used to embed a components html into some html required for the tooltip, if there are in fact any tooltips for the given help topics. More...
 

Detailed Description

This class is supposed to unify rendering of tooltips over all components and should also be usable by legacy UI components.

Definition at line 30 of file TooltipRenderer.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\UI\Implementation\Render\TooltipRenderer::__construct ( protected HelpTextRetriever  $help_text_retriever,
protected  $get_template 
)

Definition at line 32 of file TooltipRenderer.php.

35  {
36  if (!is_callable($this->get_template)) {
37  throw new \InvalidArgumentException("\$get_template should be callable.");
38  }
39  }

Member Function Documentation

◆ maybeGetTooltipEmbedding()

ILIAS\UI\Implementation\Render\TooltipRenderer::maybeGetTooltipEmbedding ( Help\Topic ...  $topics)

This will provide functions that can be used to embed a components html into some html required for the tooltip, if there are in fact any tooltips for the given help topics.

The first resulting function takes an id to be used as the tooltips id and the html of the component. The second resulting function takes the id of the component and creates an appropriate javascript to bind the required javascript to the component.

If there are no tooltips for the help topic, this will return nothing.

Returns
?((string, string) -> string, string -> string)

Definition at line 53 of file TooltipRenderer.php.

References $id, and null.

53  : ?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  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

The documentation for this class was generated from the following file: