ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
TooltipRenderer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25
31{
32 protected const string ROLE_TOOLTIP = 'tooltip';
33 protected const string ROLE_STATUS = 'status';
34
35 public function __construct(
36 protected HelpTextRetriever $help_text_retriever,
37 protected $get_template
38 ) {
39 if (!is_callable($this->get_template)) {
40 throw new \InvalidArgumentException("\$get_template should be callable.");
41 }
42 }
43
66 public function getHelpTopicTooltipEmbedding(Help\Topic ...$topics): ?array
67 {
68 if (count($topics) === 0) {
69 return null;
70 }
71
72 $tooltips = $this->help_text_retriever->getHelpText(Help\Purpose::Tooltip(), ...$topics);
73 if (count($tooltips) === 0) {
74 return null;
75 }
76
77 $get_template = $this->get_template;
78 $embed_html = static function (string $tooltip_id, string $component_html) use ($tooltips, $get_template): string {
79 $tpl = $get_template("components/ILIAS/UI/src/templates/default/tpl.tooltip.html", true, true);
80 $tpl->setVariable("COMPONENT_HTML", $component_html);
81 $tpl->setVariable("TOOLTIP_ROLE", self::ROLE_TOOLTIP);
82 $tpl->setVariable("TOOLTIP_ID", $tooltip_id);
83
84 foreach ($tooltips as $tooltip) {
85 $tpl->setCurrentBlock("tooltip");
86 $tpl->setVariable("TOOLTIP", $tooltip);
88 }
89
90 return $tpl->get();
91 };
92
93 $embed_js = static function (string $id) {
94 return "il.UI.Tooltip.createHoverTooltip(document.getElementById('$id'));";
95 };
96
97 return [$embed_html, $embed_js];
98 }
99
119 public function getStatusTooltipEmbedding(string $tooltip): array
120 {
121 $get_template = $this->get_template;
122 $embed_html = static function (string $tooltip_id, string $component_html) use ($tooltip, $get_template): string {
123 $tpl = $get_template("components/ILIAS/UI/src/templates/default/tpl.tooltip.html", true, true);
124 $tpl->setVariable("COMPONENT_HTML", $component_html);
125 $tpl->setVariable("TOOLTIP_ROLE", self::ROLE_STATUS);
126 $tpl->setVariable("TOOLTIP_ID", $tooltip_id);
127 $tpl->setVariable("TOOLTIP", $tooltip);
128
129 return $tpl->get();
130 };
131
132 $embed_js = static function (string $component_id) {
133 return "il.UI.Tooltip.createClickTooltip(document.getElementById('$component_id'));";
134 };
135
136 return [$embed_html, $embed_js];
137 }
138}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This is just a class that marks a string as a help topic.
Definition: Topic.php:27
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)
setVariable(string $variable, $value='')
Sets the given variable to the given value.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
This describes a facility that the UI framework can use to retrieve some help text.
readonly ilGlobalTemplateInterface $tpl