ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
with_toast.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
14 function with_toast(): string
15 {
16  global $DIC;
17  $tc = $DIC->ui()->factory()->toast()->container();
18 
19  $toasts = [
20  $DIC->ui()->factory()->toast()->standard(
21  'Example',
22  $DIC->ui()->factory()->symbol()->icon()->standard('info', 'Test')
23  )
24  ];
25 
26  $toasts = base64_encode($DIC->ui()->renderer()->renderAsync($toasts));
27  $button = $DIC->ui()->factory()->button()->standard($DIC->language()->txt('show'), '');
28  $button = $button->withAdditionalOnLoadCode(function ($id) use ($toasts) {
29  return "$id.addEventListener('click', () => {
30  $id.parentNode.querySelector('.il-toast-container').innerHTML = atob('$toasts');
31  $id.parentNode.querySelector('.il-toast-container').querySelectorAll('script').forEach(element => {
32  let newScript = document.createElement('script');
33  newScript.innerHTML = element.innerHTML;
34  element.parentNode.appendChild(newScript);
35  })
36  });";
37  });
38 
39  return $DIC->ui()->renderer()->render([$button,$tc]);
40 }
global $DIC
Definition: shib_login.php:25
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
with_toast()
expected output: > ILIAS shows a blue button.
Definition: with_toast.php:14