ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
with_toast.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
30 function with_toast(): string
31 {
32  global $DIC;
33  $tc = $DIC->ui()->factory()->toast()->container();
34 
35  $toasts = [
36  $DIC->ui()->factory()->toast()->standard(
37  'Example',
38  $DIC->ui()->factory()->symbol()->icon()->standard('info', 'Test')
39  )
40  ];
41 
42  $toasts = base64_encode($DIC->ui()->renderer()->renderAsync($toasts));
43  $button = $DIC->ui()->factory()->button()->standard($DIC->language()->txt('show'), '');
44  $button = $button->withAdditionalOnLoadCode(function ($id) use ($toasts) {
45  return "$id.addEventListener('click', () => {
46  $id.parentNode.querySelector('.il-toast-container').innerHTML = atob('$toasts');
47  $id.parentNode.querySelector('.il-toast-container').querySelectorAll('script').forEach(element => {
48  let newScript = document.createElement('script');
49  newScript.innerHTML = element.innerHTML;
50  element.parentNode.appendChild(newScript);
51  })
52  });";
53  });
54 
55  return $DIC->ui()->renderer()->render([$button,$tc]);
56 }
global $DIC
Definition: shib_login.php:22
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
with_toast()
expected output: > ILIAS shows a blue button.
Definition: with_toast.php:30