ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
show_modal_on_button_click.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
19 {
20  global $DIC;
21  $factory = $DIC->ui()->factory();
22  $renderer = $DIC->ui()->renderer();
23  $refinery = $DIC->refinery();
24  $request_wrapper = $DIC->http()->wrapper()->query();
25  $post_wrapper = $DIC->http()->wrapper()->post();
26  $ctrl = $DIC->ctrl();
27 
28  $message = 'Are you sure you want to delete the following items?';
29  $ctrl->setParameterByClass('ilsystemstyledocumentationgui', 'modal_nr', 1);
30  $form_action = $ctrl->getFormActionByClass('ilsystemstyledocumentationgui');
31  $icon = $factory->image()->standard('./assets/images/standard/icon_crs.svg', '');
32 
33  $items = [
34  $factory->modal()->interruptiveItem()->standard('10', 'Course 1', $icon, 'Some description text'),
35  $factory->modal()->interruptiveItem()->keyValue('20', 'Item Key', 'item value'),
36  $factory->modal()->interruptiveItem()->standard('30', 'Course 3', $icon, 'Last but not least, a description'),
37  $factory->modal()->interruptiveItem()->keyValue('50', 'Second Item Key', 'another item value'),
38  ];
39  $modal = $factory->modal()->interruptive('My Title', $message, $form_action)->withAffectedItems($items);
40  $button = $factory->button()->standard('Show Modal', '')
41  ->withOnClick($modal->getShowSignal());
42 
43  $out = [$button, $modal];
44 
45  // Display POST data of affected items in a panel
46  if (
47  $post_wrapper->has('interruptive_items') &&
48  $request_wrapper->retrieve('modal_nr', $refinery->kindlyTo()->string()) === '1'
49  ) {
50  $out[] = $post_wrapper->retrieve('interruptive_items', $refinery->custom()->transformation(
51  function ($item_keys) use ($factory, $post_wrapper) {
52  return $factory->panel()->standard('Items deleted', $factory->legacy("Number of items deleted: ".count($item_keys)));
53  }
54  ));
55  }
56 
57  return $renderer->render($out);
58 }
$renderer
show_modal_on_button_click()
description: > Example for rendering a interruptive modal on a click onto a button.
$out
Definition: buildRTE.php:24
global $DIC
Definition: shib_login.php:25