You are here

public function WebformEntityPrintRequestSubscriber::requestSetViewMode in Webform 8.5

Same name and namespace in other branches
  1. 6.x modules/webform_entity_print/src/EventSubscriber/WebformEntityPrintRequestSubscriber.php \Drupal\webform_entity_print\EventSubscriber\WebformEntityPrintRequestSubscriber::requestSetViewMode()

Set custom webform entity print submission view mode.

File

modules/webform_entity_print/src/EventSubscriber/WebformEntityPrintRequestSubscriber.php, line 36

Class

WebformEntityPrintRequestSubscriber
Event subscriber to alter requests.

Namespace

Drupal\webform_entity_print\EventSubscriber

Code

public function requestSetViewMode(GetResponseEvent $event) {
  if ($event
    ->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
    return;
  }

  // Check if current route is an entity print view.
  $route_name = $this->routeMatch
    ->getRouteName();
  if (!in_array($route_name, [
    'entity_print.view.debug',
    'entity_print.view',
  ])) {
    return;
  }

  // Get view mode from current request.
  // @see _webform_entity_print_webform_submission_links()
  $request = $event
    ->getRequest();
  if ($view_mode = $request->query
    ->get('view_mode')) {
    $request->request
      ->set('_webform_submissions_view_mode', $view_mode);
  }
}