You are here

public function TeamInactiveStatusSubscriber::onRespond in Apigee Edge 8

Display an error message on inactive team routes.

Parameters

\Symfony\Component\HttpKernel\Event\FilterResponseEvent $event: The event to process.

File

modules/apigee_edge_teams/src/EventSubscriber/TeamInactiveStatusSubscriber.php, line 93

Class

TeamInactiveStatusSubscriber
Displays an error message on team pages if team is inactive.

Namespace

Drupal\apigee_edge_teams\EventSubscriber

Code

public function onRespond(FilterResponseEvent $event) {
  if ($this->currentUser
    ->isAnonymous() || !in_array($this->routeMatch
    ->getRouteName(), $this
    ->getDisabledRoutes())) {
    return;
  }

  /** @var \Drupal\apigee_edge_teams\Entity\TeamInterface $team */
  $team = $this->routeMatch
    ->getParameter('team');
  if (!$team || $team
    ->getStatus() !== TeamInterface::STATUS_INACTIVE) {
    return;
  }
  $content = [
    'content' => [
      '#theme' => 'status_messages',
      '#message_list' => [
        'error' => [
          $this
            ->t('The %team_name @team is inactive. This operation is now allowed.', [
            '%team_name' => $team
              ->label(),
            '@team' => $team
              ->getEntityType()
              ->getSingularLabel(),
          ]),
        ],
      ],
    ],
  ];
  $renderer = $this->classResolver
    ->getInstanceFromDefinition($this->mainContentRenderers['html']);

  /* @var \Symfony\Component\HttpFoundation\Response $response */
  $response = $renderer
    ->renderResponse($content, $event
    ->getRequest(), $this->routeMatch);
  $response
    ->setStatusCode(Response::HTTP_FORBIDDEN);
  $event
    ->setResponse($response);
}