You are here

class WebformEntityPrintRequestSubscriber 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

Event subscriber to alter requests.

Hierarchy

Expanded class hierarchy of WebformEntityPrintRequestSubscriber

1 string reference to 'WebformEntityPrintRequestSubscriber'
webform_entity_print.services.yml in modules/webform_entity_print/webform_entity_print.services.yml
modules/webform_entity_print/webform_entity_print.services.yml
1 service uses WebformEntityPrintRequestSubscriber
webform_entity_print.request_subscriber in modules/webform_entity_print/webform_entity_print.services.yml
Drupal\webform_entity_print\EventSubscriber\WebformEntityPrintRequestSubscriber

File

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

Namespace

Drupal\webform_entity_print\EventSubscriber
View source
class WebformEntityPrintRequestSubscriber implements EventSubscriberInterface {

  /**
   * The current route match.
   *
   * @var \Drupal\Core\Routing\RouteMatchInterface
   */
  protected $routeMatch;

  /**
   * Constructs a new WebformEntityPrintRequestSubscriber.
   *
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   The current route match.
   */
  public function __construct(RouteMatchInterface $route_match) {
    $this->routeMatch = $route_match;
  }

  /**
   * Set custom webform entity print submission view mode.
   */
  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);
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    return [
      KernelEvents::REQUEST => 'requestSetViewMode',
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
WebformEntityPrintRequestSubscriber::$routeMatch protected property The current route match.
WebformEntityPrintRequestSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
WebformEntityPrintRequestSubscriber::requestSetViewMode public function Set custom webform entity print submission view mode.
WebformEntityPrintRequestSubscriber::__construct public function Constructs a new WebformEntityPrintRequestSubscriber.