ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
show_modal_on_button_click.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
35 {
36  global $DIC;
37  $factory = $DIC->ui()->factory();
38  $renderer = $DIC->ui()->renderer();
39  $refinery = $DIC->refinery();
40  $request_wrapper = $DIC->http()->wrapper()->query();
41  $post_wrapper = $DIC->http()->wrapper()->post();
42  $ctrl = $DIC->ctrl();
43 
44  $message = 'Are you sure you want to delete the following items?';
45  $ctrl->setParameterByClass('ilsystemstyledocumentationgui', 'modal_nr', 1);
46  $form_action = $ctrl->getFormActionByClass('ilsystemstyledocumentationgui');
47  $icon = $factory->image()->standard('./assets/images/standard/icon_crs.svg', '');
48 
49  $items = [
50  $factory->modal()->interruptiveItem()->standard('10', 'Course 1', $icon, 'Some description text'),
51  $factory->modal()->interruptiveItem()->keyValue('20', 'Item Key', 'item value'),
52  $factory->modal()->interruptiveItem()->standard('30', 'Course 3', $icon, 'Last but not least, a description'),
53  $factory->modal()->interruptiveItem()->keyValue('50', 'Second Item Key', 'another item value'),
54  ];
55  $modal = $factory->modal()->interruptive('My Title', $message, $form_action)->withAffectedItems($items);
56  $button = $factory->button()->standard('Show Modal', '')
57  ->withOnClick($modal->getShowSignal());
58 
59  $out = [$button, $modal];
60 
61  // Display POST data of affected items in a panel
62  if (
63  $post_wrapper->has('interruptive_items') &&
64  $request_wrapper->retrieve('modal_nr', $refinery->kindlyTo()->string()) === '1'
65  ) {
66  $out[] = $post_wrapper->retrieve('interruptive_items', $refinery->custom()->transformation(
67  function ($item_keys) use ($factory, $post_wrapper) {
68  return $factory->panel()->standard('Items deleted', $factory->legacy("Number of items deleted: ".count($item_keys)));
69  }
70  ));
71  }
72 
73  return $renderer->render($out);
74 }
$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:22
$message
Definition: xapiexit.php:31