ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
show_popover_with_dynamic_changing_content.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
8 
22 {
23  global $DIC;
24  $factory = $DIC->ui()->factory();
25  $renderer = $DIC->ui()->renderer();
26  $refinery = $DIC->refinery();
27  $request_wrapper = $DIC->http()->wrapper()->query();
28 
29  // This example shows how to change the content of a popover dynamically with ajax requests.
30  // Each popover offers a signal to replace its content, similar to the show signal which shows the popover.
31  // The replace signal will load the new content via ajax from a given URL and insert it into the popover.
32 
33  // The popover in this example initially shows three buttons. Each button will replace the content
34  // of the popover with a new "page" showing some text. Each page also contains a back button which
35  // again replaces the content of the popover with the overview page.
36 
37  $url = $_SERVER['REQUEST_URI'];
38 
39  // This is an ajax request to render the overview page showing the three buttons
40  if ($request_wrapper->has('page') && $request_wrapper->retrieve('page', $refinery->kindlyTo()->string()) == 'overview') {
41  // Note: The ID of the replace signal is sent explicitly as GET parameter. This is a proof of concept
42  // and may be subject to change, as the framework could send such parameters implicitly.
43  $signalId = $request_wrapper->retrieve('replaceSignal', $refinery->kindlyTo()->string());
44  $replaceSignal = new ReplaceContentSignal($signalId);
45  $button1 = $factory->button()->standard('Go to page 1', '#')
46  ->withOnClick($replaceSignal->withAsyncRenderUrl($url . '&page=1&replaceSignal=' . $signalId));
47  $button2 = $factory->button()->standard('Go to page 2', '#')
48  ->withOnClick($replaceSignal->withAsyncRenderUrl($url . '&page=2&replaceSignal=' . $signalId));
49  $button3 = $factory->button()->standard('Go to page 3', '#')
50  ->withOnClick($replaceSignal->withAsyncRenderUrl($url . '&page=3&replaceSignal=' . $signalId));
51  $list = $factory->listing()->unordered([$button1, $button2, $button3]);
52  echo $renderer->renderAsync($list);
53  exit();
54  }
55 
56  // This is an ajax request to render a page
57  if ($request_wrapper->has('page')) {
58  $page = $request_wrapper->retrieve('page', $refinery->kindlyTo()->int());
59  $signalId = $request_wrapper->retrieve('replaceSignal', $refinery->kindlyTo()->string());
60  $replaceSignal = new ReplaceContentSignal($signalId);
61  $button = $factory->button()->standard('Back to Overview', '#')
62  ->withOnClick($replaceSignal->withAsyncRenderUrl($url . '&page=overview&replaceSignal=' . $signalId));
63  $intro = $factory->legacy("<p>You are viewing page $page</p>");
64  echo $renderer->renderAsync([$intro, $button]);
65  exit();
66  }
67 
68  // This is the "normal" request to render the popover. Any content of the popover is rendered async.
69  $popover = $factory->popover()->standard($factory->legacy(''))->withTitle('Pages');
70  $asyncUrl = $url . '&page=overview&replaceSignal=' . $popover->getReplaceContentSignal()->getId();
71  $popover = $popover->withAsyncContentUrl($asyncUrl);
72  $button = $factory->button()->standard('Show Popover', '#')
73  ->withOnClick($popover->getShowSignal());
74  return $renderer->render([$popover, $button]);
75 }
$renderer
$url
Definition: shib_logout.php:63
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
global $DIC
Definition: shib_login.php:25
show_popover_with_dynamic_changing_content()
description: > Example for rendering a standard popover with dynamic changing content.