19 declare(strict_types=1);
48 if ($component->getAsyncRenderUrl()) {
55 return $this->renderRoundTrip($component, $default_renderer);
59 throw new \LogicException(self::class .
" cannot render component '" . get_class($component) .
"'.");
67 parent::registerResources($registry);
68 $registry->
register(
'./src/UI/templates/js/Modal/modal.js');
73 $show = $modal->getShowSignal();
74 $close = $modal->getCloseSignal();
78 $replace = $modal->getReplaceSignal();
82 'ajaxRenderUrl' => $modal->getAsyncRenderUrl(),
83 'keyboard' => $modal->getCloseWithKeyboard()
101 return $modal->withAdditionalOnLoadCode(
function (
$id) use ($show, $close, $options, $replace):
string {
102 $options[
"url"] =
"#$id";
103 $options = json_encode($options);
105 "$(document).on('$show', function(event, signalData) { il.UI.modal.showModal('$id', $options, signalData);});" .
106 "$(document).on('$close', function() { il.UI.modal.closeModal('$id');});";
107 if ($replace !=
"") {
108 $code .=
"$(document).on('$replace', function(event, signalData) { il.UI.modal.replaceFromSignal('$id', signalData);});";
118 return "<span id='$id'></span>";
125 $tpl = $this->
getTemplate(
'tpl.interruptive.html',
true,
true);
128 $tpl->setVariable(
'ID',
$id);
129 $value = $modal->getFormAction();
130 $tpl->setVariable(
'FORM_ACTION', $value);
131 $tpl->setVariable(
'TITLE', $modal->getTitle());
132 $tpl->setVariable(
'MESSAGE', $modal->getMessage());
136 $modal->getAffectedItems(),
139 if ($standard_items) {
140 $tpl->setCurrentBlock(
'with_standard_items');
141 $tpl->setVariable(
'STANDARD_ITEMS', $standard_items);
146 $modal->getAffectedItems(),
149 if ($key_value_items) {
150 $tpl->setCurrentBlock(
'with_key_value_items');
151 $tpl->setVariable(
'KEY_VALUE_ITEMS', $key_value_items);
154 $tpl->setVariable(
'ACTION_BUTTON_LABEL', $modal->getActionButtonLabel() ?? $this->
txt(
'delete'));
155 $tpl->setVariable(
'CANCEL_BUTTON_LABEL', $modal->getCancelButtonLabel() ?? $this->
txt(
'cancel'));
156 $tpl->setVariable(
'CLOSE_LABEL', $modal->getCancelButtonLabel() ?? $this->
txt(
'cancel'));
173 $items_of_class = array_filter(
175 fn($i) => $i instanceof $class_name
177 $rendered_items =
'';
178 foreach ($items_of_class as $item) {
179 $rendered_items .= $default_renderer->render($item);
181 return $rendered_items;
186 $tpl = $this->
getTemplate(
'tpl.roundtrip.html',
true,
true);
190 $tpl->setVariable(
'ID',
$id);
191 $tpl->setVariable(
'TITLE', $modal->getTitle());
192 $tpl->setVariable(
'CLOSE_LABEL', $this->
txt(
'close'));
194 foreach ($modal->getContent() as $content) {
195 $tpl->setCurrentBlock(
'with_content');
196 $tpl->setVariable(
'CONTENT', $default_renderer->render($content));
197 $tpl->parseCurrentBlock();
199 foreach ($modal->getActionButtons() as $button) {
200 $tpl->setCurrentBlock(
'with_buttons');
201 $tpl->setVariable(
'BUTTON', $default_renderer->render($button));
202 $tpl->parseCurrentBlock();
206 if (!empty($modal->getInputs())) {
208 $tpl->setCurrentBlock(
'with_form');
209 $tpl->setVariable(
'FORM', $default_renderer->render($modal->getForm()));
210 $tpl->parseCurrentBlock();
214 $modal->getSubmitLabel() ?? $this->
txt(
'save'),
216 )->withOnClick($modal->getForm()->getSubmitSignal());
217 $tpl->setCurrentBlock(
'with_submit');
218 $tpl->setVariable(
'SUBMIT_BUTTON', $default_renderer->render($submit));
219 $tpl->parseCurrentBlock();
222 $tpl->setVariable(
'CANCEL_BUTTON_LABEL', $modal->getCancelButtonLabel() ?? $this->
txt(
'cancel'));
228 $tpl = $this->
getTemplate(
'tpl.lightbox.html',
true,
true);
231 $tpl->setVariable(
'ID',
$id);
232 $id_carousel =
"{$id}_carousel";
233 $pages = $modal->getPages();
234 $tpl->setVariable(
'TITLE', $pages[0]->getTitle());
235 $tpl->setVariable(
'ID_CAROUSEL', $id_carousel);
236 $tpl->setVariable(
'CLOSE_LABEL', $this->
txt(
'close'));
237 $tpl->setVariable(
'COLOR_SCHEME', $modal->getScheme());
239 if (count($pages) > 1) {
240 $tpl->setCurrentBlock(
'has_indicators');
241 foreach ($pages as $index => $page) {
242 $tpl->setCurrentBlock(
'indicators');
243 $tpl->setVariable(
'INDEX', $index);
244 $tpl->setVariable(
'CLASS_ACTIVE', ($index == 0) ?
'active' :
'');
245 $tpl->setVariable(
'ID_CAROUSEL2', $id_carousel);
246 $tpl->parseCurrentBlock();
250 foreach ($pages as $page) {
251 $this->
renderPage($page, $first, $tpl, $default_renderer);
254 if (count($pages) > 1) {
255 $tpl->setCurrentBlock(
'controls');
256 $tpl->setVariable(
'ID_CAROUSEL3', $id_carousel);
257 $tpl->parseCurrentBlock();
259 $tpl->setVariable(
'ID_CAROUSEL4', $id_carousel);
284 $components = array_merge(
291 $tpl->
setVariable(
'CLASS_ACTIVE', $first ?
'active' :
'');
292 $tpl->
setVariable(
'ORIENTATION', $vertical ?
'item-vertical' :
'');
294 $tpl->
setVariable(
'CONTENT', $default_renderer->render($components));
296 $tpl->
setVariable(
'DESCRIPTION', $page->getDescription());
Registry for resources required by rendered output like Javascript or CSS.
Interface InterruptiveItem.
checkComponent(Component $component)
Check if a given component fits this renderer and throw if that is not the case. ...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
renderPage(LightboxPage $page, bool $first, Template $tpl, RendererInterface $default_renderer)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
txt(string $id)
Get a text from the language file.
setCurrentBlock(string $name)
Set the block to work on.
getTitle()
Get the title of this page, displayed as title in the lightbox modal.
setVariable(string $name, $value)
Set a variable in the current block.
renderLightbox(Component\Modal\Lightbox $modal, RendererInterface $default_renderer)
registerResources(ResourceRegistry $registry)
Announce resources this renderer requires.
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
renderInterruptive(Component\Modal\Interruptive $modal, RendererInterface $default_renderer)
register(string $name)
Add a dependency.
getComponent()
Get the component representing the media item to be displayed in the modals content section...
parseCurrentBlock()
Parse the block that is currently worked on.
render(Component $component, Renderer $default_renderer)
Render the component if possible and delegate additional rendering to the default_renderer.
Interface LightboxDescriptionEnabledPage.
renderAsync(Component\Modal\Modal $modal)
touchBlock(string $name)
Touch a block without working further on it.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
getUIFactory()
Get a UI factory.
renderInterruptiveItemsByClass(string $class_name, array $items, RendererInterface $default_renderer)
Filters items by provided class, and renders only those.
Base class for all component renderers.
registerSignals(Component\Modal\Modal $modal)
getComponentInterfaceName()
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.