Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / system / tests / modules / dialog_renderer_test / src / Render / MainContent / WideModalRenderer.php
1 <?php
2
3 namespace Drupal\dialog_renderer_test\Render\MainContent;
4
5 use Drupal\Core\Ajax\AjaxResponse;
6 use Drupal\Core\Ajax\OpenModalDialogCommand;
7 use Drupal\Core\Controller\TitleResolverInterface;
8 use Drupal\Core\Render\MainContent\ModalRenderer;
9 use Drupal\Core\Routing\RouteMatchInterface;
10 use Symfony\Component\HttpFoundation\Request;
11
12 /**
13  * Default main content renderer for wide modal dialog requests.
14  *
15  * This test class is copied from \Drupal\Core\Render\MainContent\ModalRenderer
16  * to demonstrate selecting a different render via 'data-dialog-renderer' link
17  * attribute.
18  */
19 class WideModalRenderer extends ModalRenderer {
20
21   /**
22    * The mode, either 'wide' or 'extra_wide'.
23    *
24    * @var string
25    */
26   protected $mode;
27
28   /**
29    * Constructs a new WideModalRenderer.
30    *
31    * @param \Drupal\Core\Controller\TitleResolverInterface $title_resolver
32    *   The title resolver.
33    * @param string $mode
34    *   The mode, either 'wide' or 'extra_wide'.
35    */
36   public function __construct(TitleResolverInterface $title_resolver, $mode = 'wide') {
37     parent::__construct($title_resolver);
38     $this->mode = $mode;
39   }
40
41
42   /**
43    * {@inheritdoc}
44    */
45   public function renderResponse(array $main_content, Request $request, RouteMatchInterface $route_match) {
46     $response = new AjaxResponse();
47
48     // First render the main content, because it might provide a title.
49     $content = drupal_render_root($main_content);
50
51     // Attach the library necessary for using the OpenModalDialogCommand and set
52     // the attachments for this Ajax response.
53     $main_content['#attached']['library'][] = 'core/drupal.dialog.ajax';
54     $response->setAttachments($main_content['#attached']);
55
56     // If the main content doesn't provide a title, use the title resolver.
57     $title = isset($main_content['#title']) ? $main_content['#title'] : $this->titleResolver->getTitle($request, $route_match->getRouteObject());
58
59     // Determine the title: use the title provided by the main content if any,
60     // otherwise get it from the routing information.
61     $options = $request->request->get('dialogOptions', []);
62     // Override width option.
63     switch ($this->mode) {
64       case 'wide':
65         $options['width'] = 700;
66         break;
67
68       case 'extra_wide':
69         $options['width'] = 1000;
70         break;
71     }
72
73     $response->addCommand(new OpenModalDialogCommand($title, $content, $options));
74     return $response;
75   }
76
77 }