ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\UI\Examples\Popover\Standard Namespace Reference

Functions

 show_popover_with_dynamic_changing_content ()
 

Function Documentation

◆ show_popover_with_dynamic_changing_content()

ILIAS\UI\Examples\Popover\Standard\show_popover_with_dynamic_changing_content ( )

description: > Example for rendering a standard popover with dynamic changing content.

expected output: > ILIAS shows a button titled "Show Popover". A click onto the button opens the popover including buttons. You can navigate through the popover content by clicking those buttons.

You can close the popover by clicking onto the ILIAS background outside of the popover.

Definition at line 37 of file show_popover_with_dynamic_changing_content.php.

38{
39 global $DIC;
40 $factory = $DIC->ui()->factory();
41 $renderer = $DIC->ui()->renderer();
42 $refinery = $DIC->refinery();
43 $request_wrapper = $DIC->http()->wrapper()->query();
44
45 // This example shows how to change the content of a popover dynamically with ajax requests.
46 // Each popover offers a signal to replace its content, similar to the show signal which shows the popover.
47 // The replace signal will load the new content via ajax from a given URL and insert it into the popover.
48
49 // The popover in this example initially shows three buttons. Each button will replace the content
50 // of the popover with a new "page" showing some text. Each page also contains a back button which
51 // again replaces the content of the popover with the overview page.
52
53 $url = $_SERVER['REQUEST_URI'];
54
55 // This is an ajax request to render the overview page showing the three buttons
56 if ($request_wrapper->has('page') && $request_wrapper->retrieve('page', $refinery->kindlyTo()->string()) == 'overview') {
57 // Note: The ID of the replace signal is sent explicitly as GET parameter. This is a proof of concept
58 // and may be subject to change, as the framework could send such parameters implicitly.
59 $signalId = $request_wrapper->retrieve('replaceSignal', $refinery->kindlyTo()->string());
60 $replaceSignal = new ReplaceContentSignal($signalId);
61 $button1 = $factory->button()->standard('Go to page 1', '#')
62 ->withOnClick($replaceSignal->withAsyncRenderUrl($url . '&page=1&replaceSignal=' . $signalId));
63 $button2 = $factory->button()->standard('Go to page 2', '#')
64 ->withOnClick($replaceSignal->withAsyncRenderUrl($url . '&page=2&replaceSignal=' . $signalId));
65 $button3 = $factory->button()->standard('Go to page 3', '#')
66 ->withOnClick($replaceSignal->withAsyncRenderUrl($url . '&page=3&replaceSignal=' . $signalId));
67 $list = $factory->listing()->unordered([$button1, $button2, $button3]);
68 echo $renderer->renderAsync($list);
69 exit();
70 }
71
72 // This is an ajax request to render a page
73 if ($request_wrapper->has('page')) {
74 $page = $request_wrapper->retrieve('page', $refinery->kindlyTo()->int());
75 $signalId = $request_wrapper->retrieve('replaceSignal', $refinery->kindlyTo()->string());
76 $replaceSignal = new ReplaceContentSignal($signalId);
77 $button = $factory->button()->standard('Back to Overview', '#')
78 ->withOnClick($replaceSignal->withAsyncRenderUrl($url . '&page=overview&replaceSignal=' . $signalId));
79 $intro = $factory->legacy()->content("<p>You are viewing page $page</p>");
80 echo $renderer->renderAsync([$intro, $button]);
81 exit();
82 }
83
84 // This is the "normal" request to render the popover. Any content of the popover is rendered async.
85 $popover = $factory->popover()->standard($factory->legacy()->content(''))->withTitle('Pages');
86 $asyncUrl = $url . '&page=overview&replaceSignal=' . $popover->getReplaceContentSignal()->getId();
87 $popover = $popover->withAsyncContentUrl($asyncUrl);
88 $button = $factory->button()->standard('Show Popover', '#')
89 ->withOnClick($popover->getShowSignal());
90 return $renderer->render([$popover, $button]);
91}
$renderer
exit
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26
global $DIC
Definition: shib_login.php:26
$url
Definition: shib_logout.php:68

References $_SERVER, $DIC, ILIAS\UI\examples\Layout\Page\Standard\$refinery, $renderer, ILIAS\UI\examples\Layout\Page\Standard\$request_wrapper, $url, and exit.