Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/views/src/Routing/ViewPageController.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\views\Routing; | |
4 | |
5 use Drupal\Core\Routing\RouteMatchInterface; | |
6 use Drupal\views\Plugin\views\display\Page; | |
7 | |
8 /** | |
9 * Defines a page controller to execute and render a view. | |
10 */ | |
11 class ViewPageController { | |
12 | |
13 /** | |
14 * Handler a response for a given view and display. | |
15 * | |
16 * @param string $view_id | |
17 * The ID of the view | |
18 * @param string $display_id | |
19 * The ID of the display. | |
20 * @param \Drupal\Core\Routing\RouteMatchInterface $route_match | |
21 * The route match. | |
22 * @return null|void | |
23 */ | |
24 public function handle($view_id, $display_id, RouteMatchInterface $route_match) { | |
25 $args = []; | |
26 $route = $route_match->getRouteObject(); | |
27 $map = $route->hasOption('_view_argument_map') ? $route->getOption('_view_argument_map') : []; | |
28 | |
29 foreach ($map as $attribute => $parameter_name) { | |
30 // Allow parameters be pulled from the request. | |
31 // The map stores the actual name of the parameter in the request. Views | |
32 // which override existing controller, use for example 'node' instead of | |
33 // arg_nid as name. | |
34 if (isset($map[$attribute])) { | |
35 $attribute = $map[$attribute]; | |
36 } | |
37 if ($arg = $route_match->getRawParameter($attribute)) { | |
38 } | |
39 else { | |
40 $arg = $route_match->getParameter($attribute); | |
41 } | |
42 | |
43 if (isset($arg)) { | |
44 $args[] = $arg; | |
45 } | |
46 } | |
47 | |
48 /** @var \Drupal\views\Plugin\views\display\DisplayPluginBase $class */ | |
49 $class = $route->getOption('_view_display_plugin_class'); | |
50 if ($route->getOption('returns_response')) { | |
51 /** @var \Drupal\views\Plugin\views\display\ResponseDisplayPluginInterface $class */ | |
52 return $class::buildResponse($view_id, $display_id, $args); | |
53 } | |
54 else { | |
55 $build = $class::buildBasicRenderable($view_id, $display_id, $args, $route); | |
56 Page::setPageRenderArray($build); | |
57 | |
58 views_add_contextual_links($build, 'page', $display_id, $build); | |
59 | |
60 return $build; | |
61 } | |
62 } | |
63 | |
64 } |