19declare(strict_types=1);
52 return $this->
renderButton($component, $default_renderer);
61 $tpl_name =
"tpl.primary.html";
64 $tpl_name =
"tpl.standard.html";
67 $tpl_name =
"tpl.shy.html";
70 $tpl_name =
"tpl.tag.html";
73 $tpl_name =
"tpl.bulky.html";
80 $action = $component->getAction();
83 if (is_string($action)) {
84 $tpl->setCurrentBlock(
"with_data_action");
85 $tpl->setVariable(
"ACTION", $action);
86 $tpl->parseCurrentBlock();
89 $tpl->setVariable(
"LABEL", $component->getLabel());
90 $symbol = $component->getSymbol();
91 if ($symbol !==
null) {
93 if (
'' === $component->getLabel() &&
'' === $component->getAriaLabel()) {
94 $component = $component->withAriaLabel($this->
getSymbolLabel($symbol));
97 $symbol = $symbol->withLabel(
'');
98 $tpl->setVariable(
"SYMBOL", $default_renderer->render($symbol));
101 if ($component->isActive()) {
104 if (is_string($action) && $action !=
"") {
105 $component = $component->withAdditionalOnLoadCode(
function (
$id) use ($action) {
106 $action = str_replace(
"&",
"&", $action);
108 return "$('#$id').on('click', function(event) {
109 window.location = '$action';
116 $component = $component->withAdditionalOnLoadCode(fn(
$id) =>
"$('#$id').click(function(e) { il.UI.button.activateLoadingAnimation('$id')});");
119 $tpl->touchBlock(
"disabled");
121 $aria_label = $component->getAriaLabel();
122 if ($aria_label !=
null) {
123 $tpl->setCurrentBlock(
"with_aria_label");
124 $tpl->setVariable(
"ARIA_LABEL", $aria_label);
125 $tpl->parseCurrentBlock();
131 if ($component->isEngaged()) {
132 $tpl->touchBlock(
"engaged");
133 $aria_pressed =
'true';
135 $aria_pressed =
'false';
139 if (!($component instanceof
Bulky)) {
140 $tpl->setCurrentBlock(
"with_aria_pressed");
141 $tpl->setVariable(
"ARIA_PRESSED", $aria_pressed);
142 $tpl->parseCurrentBlock();
146 $tooltip_embedding = $this->
getTooltipRenderer()->maybeGetTooltipEmbedding(...$component->getHelpTopics());
147 if ($tooltip_embedding) {
148 $component = $component->withAdditionalOnLoadCode($tooltip_embedding[1]);
161 if (!$tooltip_embedding) {
166 $tpl->setCurrentBlock(
"with_aria_describedby");
167 $tpl->setVariable(
"ARIA_DESCRIBED_BY", $tooltip_id);
168 $tpl->parseCurrentBlock();
170 return $tooltip_embedding[0]($tooltip_id, $tpl->get());
178 parent::registerResources($registry);
179 $registry->
register(
'assets/js/button.js');
180 $registry->
register(
"./assets/js/moment-with-locales.min.js");
185 $tpl = $this->
getTemplate(
"tpl.close.html",
true,
true);
188 $tpl->setVariable(
"FORCE_RENDERING",
"");
189 $tpl->setVariable(
"ARIA_LABEL", $this->
txt(
"close"));
196 $tpl = $this->
getTemplate(
"tpl.minimize.html",
true,
true);
197 $tpl->setVariable(
"ARIA_LABEL", $this->
txt(
"minimize"));
204 $tpl = $this->
getTemplate(
"tpl.toggle.html",
true,
true);
208 $on_action = $component->getActionOn();
209 $off_action = $component->getActionOff();
211 $on_url = (is_string($on_action))
215 $off_url = (is_string($off_action))
221 foreach ($component->getTriggeredSignals() as $s) {
223 "signal_id" => $s->getSignal()->getId(),
224 "event" => $s->getEvent(),
225 "options" => $s->getSignal()->getOptions()
229 $signals = json_encode($signals);
231 $button_status =
'off';
232 if ($component->isEngaged()) {
233 $button_status =
'on';
236 if ($component->isActive()) {
237 $component = $component->withAdditionalOnLoadCode(
239 "$('#$id').on('click', function(event) {
240 il.UI.button.handleToggleClick(event, '$id', '$on_url', '$off_url', $signals);
241 return false; // stop event propagation
244 $tpl->setCurrentBlock(
"with_on_off_label");
245 $tpl->setVariable(
"ON_LABEL", $this->
txt(
"toggle_on"));
246 $tpl->setVariable(
"OFF_LABEL", $this->
txt(
"toggle_off"));
247 $tpl->parseCurrentBlock();
249 $tpl->touchBlock(
"disabled");
250 $button_status =
'unavailable';
253 $tpl->touchBlock($button_status);
255 $label = $component->getLabel();
256 if (!empty($label)) {
257 $tpl->setCurrentBlock(
"with_label");
258 $tpl->setVariable(
"LABEL", $label);
259 $tpl->parseCurrentBlock();
261 $aria_label = $component->getAriaLabel();
262 if ($aria_label !=
null) {
263 $tpl->setCurrentBlock(
"with_aria_label");
264 $tpl->setVariable(
"ARIA_LABEL", $aria_label);
265 $tpl->parseCurrentBlock();
268 $tooltip_embedding = $this->
getTooltipRenderer()->maybeGetTooltipEmbedding(...$component->getHelpTopics());
269 if ($tooltip_embedding) {
270 $component = $component->withAdditionalOnLoadCode($tooltip_embedding[1]);
272 $tpl->setCurrentBlock(
"with_aria_describedby");
273 $tpl->setVariable(
"ARIA_DESCRIBED_BY", $tooltip_id);
274 $tpl->parseCurrentBlock();
277 return $tooltip_embedding[0]($tooltip_id, $tpl->get());
296 $tpl = $this->
getTemplate(
"tpl.month.html",
true,
true);
298 $component = $component->withAdditionalOnLoadCode(fn(
$id) =>
"il.UI.button.initMonth('$id');");
300 $tpl->setVariable(
"ID",
$id);
302 $def = $component->getDefault();
303 $value = implode(
'-', array_reverse(explode(
"-", $def)));
304 $tpl->setVariable(
"DEFAULT", $value);
311 $tpl->
touchBlock(
'rel_' . $component->getRelevance());
313 $classes = trim(join(
' ', $component->getClasses()));
314 if ($classes !==
'') {
318 $bgcol = $component->getBackgroundColor();
322 $forecol = $component->getForegroundColor();
330 RendererInterface $default_renderer,
333 $aria_role = $component->getAriaRole();
334 if ($aria_role !=
null) {
339 if ($component->isEngageable()) {
345 if ($component->isEngaged()) {
362 if (!$symbol instanceof
Glyph) {
366 $label = $this->txt($symbol->
getLabel());
367 foreach ($symbol->getCounters() as
$counter) {
369 $label .= $this->txt(
"counter_" .
$counter->getType()) .
" " .
$counter->getNumber() .
"; ";
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Base class for all component renderers.
cannotHandleComponent(Component $component)
This method MUST be called by derived component renderers, if.
txt(string $id)
Get a text from the language file.
createId()
Get a fresh unique id.
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.
Interface to be extended by components that have the possibility to bind to Javascript.
This describes how an icon could be modified during construction of UI.
getLabel()
Get the label of this icon.
Registry for resources required by rendered output like Javascript or CSS.
register(string $name)
Add a dependency.
Interface to templating as it is used in the UI framework.
setVariable(string $name, $value)
Set a variable in the current block.
setCurrentBlock(string $name)
Set the block to work on.
touchBlock(string $name)
Touch a block without working further on it.
parseCurrentBlock()
Parse the block that is currently worked on.
An entity that renders components to a string output.