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";
78 $action = $component->getAction();
81 if (is_string($action)) {
82 $tpl->setCurrentBlock(
"with_data_action");
83 $tpl->setVariable(
"ACTION", $action);
84 $tpl->parseCurrentBlock();
87 $tpl->setVariable(
"LABEL", $component->getLabel());
88 $symbol = $component->getSymbol();
89 if ($symbol !==
null) {
90 if ($component->getLabel() !==
'') {
91 $symbol = $symbol->withLabel(
'');
93 $tpl->setVariable(
"SYMBOL", $default_renderer->render($symbol));
96 if ($component->isActive()) {
99 if (is_string($action) && $action !=
"") {
100 $component = $component->withAdditionalOnLoadCode(
function (
$id) use ($action) {
101 $action = str_replace(
"&",
"&", $action);
103 return "$('#$id').on('click', function(event) {
104 window.location = '$action';
111 $component = $component->withAdditionalOnLoadCode(fn(
$id) =>
"$('#$id').click(function(e) { il.UI.button.activateLoadingAnimation('$id')});");
114 $tpl->touchBlock(
"disabled");
116 $aria_label = $component->getAriaLabel();
117 if ($aria_label !=
null) {
118 $tpl->setCurrentBlock(
"with_aria_label");
119 $tpl->setVariable(
"ARIA_LABEL", $aria_label);
120 $tpl->parseCurrentBlock();
126 if ($component->isEngaged()) {
127 $tpl->touchBlock(
"engaged");
128 $aria_pressed =
'true';
130 $aria_pressed =
'false';
134 if (!($component instanceof
Bulky)) {
135 $tpl->setCurrentBlock(
"with_aria_pressed");
136 $tpl->setVariable(
"ARIA_PRESSED", $aria_pressed);
137 $tpl->parseCurrentBlock();
141 $tooltip_embedding = $this->
getTooltipRenderer()->maybeGetTooltipEmbedding(...$component->getHelpTopics());
142 if ($tooltip_embedding) {
143 $component = $component->withAdditionalOnLoadCode($tooltip_embedding[1]);
156 if (!$tooltip_embedding) {
161 $tpl->setCurrentBlock(
"with_aria_describedby");
162 $tpl->setVariable(
"ARIA_DESCRIBED_BY", $tooltip_id);
163 $tpl->parseCurrentBlock();
165 return $tooltip_embedding[0]($tooltip_id, $tpl->get());
173 parent::registerResources($registry);
174 $registry->
register(
'assets/js/button.js');
175 $registry->
register(
"./assets/js/moment-with-locales.min.js");
180 $tpl = $this->
getTemplate(
"tpl.close.html",
true,
true);
183 $tpl->setVariable(
"FORCE_RENDERING",
"");
184 $tpl->setVariable(
"ARIA_LABEL", $this->
txt(
"close"));
191 $tpl = $this->
getTemplate(
"tpl.minimize.html",
true,
true);
192 $tpl->setVariable(
"ARIA_LABEL", $this->
txt(
"minimize"));
199 $tpl = $this->
getTemplate(
"tpl.toggle.html",
true,
true);
201 $on_action = $component->getActionOn();
202 $off_action = $component->getActionOff();
204 $on_url = (is_string($on_action))
208 $off_url = (is_string($off_action))
214 foreach ($component->getTriggeredSignals() as $s) {
216 "signal_id" => $s->getSignal()->getId(),
217 "event" => $s->getEvent(),
218 "options" => $s->getSignal()->getOptions()
222 $signals = json_encode($signals);
224 $button_status =
'off';
225 if ($component->isEngaged()) {
226 $button_status =
'on';
229 if ($component->isActive()) {
230 $component = $component->withAdditionalOnLoadCode(
232 "$('#$id').on('click', function(event) {
233 il.UI.button.handleToggleClick(event, '$id', '$on_url', '$off_url', $signals);
234 return false; // stop event propagation
237 $tpl->setCurrentBlock(
"with_on_off_label");
238 $tpl->setVariable(
"ON_LABEL", $this->
txt(
"toggle_on"));
239 $tpl->setVariable(
"OFF_LABEL", $this->
txt(
"toggle_off"));
240 $tpl->parseCurrentBlock();
242 $tpl->touchBlock(
"disabled");
243 $button_status =
'unavailable';
246 $tpl->touchBlock($button_status);
248 $label = $component->getLabel();
249 if (!empty($label)) {
250 $tpl->setCurrentBlock(
"with_label");
251 $tpl->setVariable(
"LABEL", $label);
252 $tpl->parseCurrentBlock();
254 $aria_label = $component->getAriaLabel();
255 if ($aria_label !=
null) {
256 $tpl->setCurrentBlock(
"with_aria_label");
257 $tpl->setVariable(
"ARIA_LABEL", $aria_label);
258 $tpl->parseCurrentBlock();
261 $tooltip_embedding = $this->
getTooltipRenderer()->maybeGetTooltipEmbedding(...$component->getHelpTopics());
262 if ($tooltip_embedding) {
263 $component = $component->withAdditionalOnLoadCode($tooltip_embedding[1]);
265 $tpl->setCurrentBlock(
"with_aria_describedby");
266 $tpl->setVariable(
"ARIA_DESCRIBED_BY", $tooltip_id);
267 $tpl->parseCurrentBlock();
270 return $tooltip_embedding[0]($tooltip_id, $tpl->get());
289 $tpl = $this->
getTemplate(
"tpl.month.html",
true,
true);
291 $component = $component->withAdditionalOnLoadCode(fn(
$id) =>
"il.UI.button.initMonth('$id');");
293 $tpl->setVariable(
"ID",
$id);
295 $def = $component->getDefault();
296 $value = implode(
'-', array_reverse(explode(
"-", $def)));
297 $tpl->setVariable(
"DEFAULT", $value);
304 $tpl->
touchBlock(
'rel_' . $component->getRelevance());
306 $classes = trim(join(
' ', $component->getClasses()));
307 if ($classes !==
'') {
311 $bgcol = $component->getBackgroundColor();
315 $forecol = $component->getForegroundColor();
323 RendererInterface $default_renderer,
326 $aria_role = $component->getAriaRole();
327 if ($aria_role !=
null) {
332 if ($component->isEngageable()) {
338 if ($component->isEngaged()) {
$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.
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.