19 declare(strict_types=1);
49 return $this->
renderButton($component, $default_renderer);
58 $tpl_name =
"tpl.primary.html";
61 $tpl_name =
"tpl.standard.html";
64 $tpl_name =
"tpl.shy.html";
67 $tpl_name =
"tpl.tag.html";
70 $tpl_name =
"tpl.bulky.html";
75 $action = $component->getAction();
78 if (is_string($action)) {
79 $tpl->setCurrentBlock(
"with_data_action");
80 $tpl->setVariable(
"ACTION", $action);
81 $tpl->parseCurrentBlock();
84 $tpl->setVariable(
"LABEL", $component->getLabel());
85 $symbol = $component->getSymbol();
86 if ($symbol !==
null) {
87 if ($component->getLabel() !==
'') {
88 $symbol = $symbol->withLabel(
'');
90 $tpl->setVariable(
"SYMBOL", $default_renderer->render($symbol));
93 if ($component->isActive()) {
96 if (is_string($action) && $action !=
"") {
97 $component = $component->withAdditionalOnLoadCode(
function (
$id) use ($action) {
98 $action = str_replace(
"&",
"&", $action);
100 return "$('#$id').on('click', function(event) { 101 window.location = '$action'; 108 $component = $component->withAdditionalOnLoadCode(fn(
$id) =>
"$('#$id').click(function(e) { il.UI.button.activateLoadingAnimation('$id')});");
111 $tpl->touchBlock(
"disabled");
113 $aria_label = $component->getAriaLabel();
114 if ($aria_label !=
null) {
115 $tpl->setCurrentBlock(
"with_aria_label");
116 $tpl->setVariable(
"ARIA_LABEL", $aria_label);
117 $tpl->parseCurrentBlock();
121 && $component->isEngageable()
123 if ($component->isEngaged()) {
124 $tpl->touchBlock(
"engaged");
125 $aria_pressed =
'true';
127 $aria_pressed =
'false';
131 if (!($component instanceof Bulky)) {
132 $tpl->setCurrentBlock(
"with_aria_pressed");
133 $tpl->setVariable(
"ARIA_PRESSED", $aria_pressed);
134 $tpl->parseCurrentBlock();
138 $tooltip_embedding = $this->
getTooltipRenderer()->maybeGetTooltipEmbedding(...$component->getHelpTopics());
139 if ($tooltip_embedding) {
140 $component = $component->withAdditionalOnLoadCode($tooltip_embedding[1]);
153 if (!$tooltip_embedding) {
158 $tpl->setCurrentBlock(
"with_aria_describedby");
159 $tpl->setVariable(
"ARIA_DESCRIBED_BY", $tooltip_id);
160 $tpl->parseCurrentBlock();
162 return $tooltip_embedding[0]($tooltip_id, $tpl->get());
170 parent::registerResources($registry);
171 $registry->
register(
'assets/js/button.js');
172 $registry->
register(
"./assets/js/moment-with-locales.min.js");
177 $tpl = $this->
getTemplate(
"tpl.close.html",
true,
true);
180 $tpl->setVariable(
"FORCE_RENDERING",
"");
181 $tpl->setVariable(
"ARIA_LABEL", $this->
txt(
"close"));
188 $tpl = $this->
getTemplate(
"tpl.minimize.html",
true,
true);
189 $tpl->setVariable(
"ARIA_LABEL", $this->
txt(
"minimize"));
196 $tpl = $this->
getTemplate(
"tpl.toggle.html",
true,
true);
198 $on_action = $component->getActionOn();
199 $off_action = $component->getActionOff();
201 $on_url = (is_string($on_action))
205 $off_url = (is_string($off_action))
211 foreach ($component->getTriggeredSignals() as $s) {
213 "signal_id" => $s->getSignal()->getId(),
214 "event" => $s->getEvent(),
215 "options" => $s->getSignal()->getOptions()
219 $signals = json_encode($signals);
221 $button_status =
'off';
222 if ($component->isEngaged()) {
223 $button_status =
'on';
226 if ($component->isActive()) {
227 $component = $component->withAdditionalOnLoadCode(
229 "$('#$id').on('click', function(event) { 230 il.UI.button.handleToggleClick(event, '$id', '$on_url', '$off_url', $signals); 231 return false; // stop event propagation 234 $tpl->setCurrentBlock(
"with_on_off_label");
235 $tpl->setVariable(
"ON_LABEL", $this->
txt(
"toggle_on"));
236 $tpl->setVariable(
"OFF_LABEL", $this->
txt(
"toggle_off"));
237 $tpl->parseCurrentBlock();
239 $tpl->touchBlock(
"disabled");
240 $button_status =
'unavailable';
243 $tpl->touchBlock($button_status);
245 $label = $component->getLabel();
246 if (!empty($label)) {
247 $tpl->setCurrentBlock(
"with_label");
248 $tpl->setVariable(
"LABEL", $label);
249 $tpl->parseCurrentBlock();
251 $aria_label = $component->getAriaLabel();
252 if ($aria_label !=
null) {
253 $tpl->setCurrentBlock(
"with_aria_label");
254 $tpl->setVariable(
"ARIA_LABEL", $aria_label);
255 $tpl->parseCurrentBlock();
258 $tooltip_embedding = $this->
getTooltipRenderer()->maybeGetTooltipEmbedding(...$component->getHelpTopics());
259 if ($tooltip_embedding) {
260 $component = $component->withAdditionalOnLoadCode($tooltip_embedding[1]);
262 $tpl->setCurrentBlock(
"with_aria_describedby");
263 $tpl->setVariable(
"ARIA_DESCRIBED_BY", $tooltip_id);
264 $tpl->parseCurrentBlock();
267 return $tooltip_embedding[0]($tooltip_id, $tpl->get());
286 $tpl = $this->
getTemplate(
"tpl.month.html",
true,
true);
288 $component = $component->withAdditionalOnLoadCode(fn(
$id) =>
"il.UI.button.initMonth('$id');");
290 $tpl->setVariable(
"ID",
$id);
292 $def = $component->getDefault();
293 $value = implode(
'-', array_reverse(explode(
"-", $def)));
294 $tpl->setVariable(
"DEFAULT", $value);
301 $tpl->
touchBlock(
'rel_' . $component->getRelevance());
303 $classes = trim(join(
' ', $component->getClasses()));
304 if ($classes !==
'') {
308 $bgcol = $component->getBackgroundColor();
312 $forecol = $component->getForegroundColor();
323 $aria_role = $component->getAriaRole();
324 if ($aria_role !=
null) {
329 if ($component->isEngageable()) {
335 if ($component->isEngaged()) {
Registry for resources required by rendered output like Javascript or CSS.
txt(string $id)
Get a text from the language file.
setCurrentBlock(string $name)
Set the block to work on.
createId()
Get a fresh unique id.
setVariable(string $name, $value)
Set a variable in the current block.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
cannotHandleComponent(Component $component)
This method MUST be called by derived component renderers, if.
register(string $name)
Add a dependency.
parseCurrentBlock()
Parse the block that is currently worked on.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
touchBlock(string $name)
Touch a block without working further on it.
Base class for all component renderers.
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.