3 namespace Drupal\views\Routing;
5 use Drupal\Core\Routing\RouteMatchInterface;
6 use Drupal\views\Plugin\views\display\Page;
9 * Defines a page controller to execute and render a view.
11 class ViewPageController {
14 * Handler a response for a given view and display.
16 * @param string $view_id
18 * @param string $display_id
19 * The ID of the display.
20 * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
24 public function handle($view_id, $display_id, RouteMatchInterface $route_match) {
26 $route = $route_match->getRouteObject();
27 $map = $route->hasOption('_view_argument_map') ? $route->getOption('_view_argument_map') : [];
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
34 if (isset($map[$attribute])) {
35 $attribute = $map[$attribute];
37 if ($arg = $route_match->getRawParameter($attribute)) {
40 $arg = $route_match->getParameter($attribute);
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);
55 $build = $class::buildBasicRenderable($view_id, $display_id, $args, $route);
56 Page::setPageRenderArray($build);
58 views_add_contextual_links($build, 'page', $display_id, $build);