You are here

public function TeamStatusWarningSubscriber::onRespond in Apigee Edge 8

Display's a warning message if team's status is inactive.

Parameters

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

File

modules/apigee_edge_teams/src/EventSubscriber/TeamStatusWarningSubscriber.php, line 100

Class

TeamStatusWarningSubscriber
Displays a warning message on team app pages if app owner is inactive.

Namespace

Drupal\apigee_edge_teams\EventSubscriber

Code

public function onRespond(FilterResponseEvent $event) {

  // Anonymous user's does not have access to these routes.
  if ($this->currentUser
    ->isAuthenticated() && strpos($this->routeMatch
    ->getRouteName(), 'entity.team_app.') === 0) {

    // Team is available in most of the team app routes as a route parameter.

    /** @var \Drupal\apigee_edge_teams\Entity\TeamInterface|NULL $team */
    $team = $this->routeMatch
      ->getParameter('team');
    if ($team === NULL) {

      /** @var \Drupal\apigee_edge_teams\Entity\TeamAppInterface $app */
      $app = $this->routeMatch
        ->getParameter('team_app') ?? $this->routeMatch
        ->getParameter('app');
      if ($app) {
        $team = $this->entityTypeManager
          ->getStorage('team')
          ->load($app
          ->getCompanyName());
      }
    }
    if ($team && $team
      ->getStatus() === TeamInterface::STATUS_INACTIVE) {
      $this->messenger
        ->addWarning($this
        ->t('This @team has inactive status so @team members will not be able to use @team_app credentials until the @team gets activated. Please contact support for further assistance.', [
        '@team' => mb_strtolower($this->entityTypeManager
          ->getDefinition('team')
          ->getSingularLabel()),
        '@team_app' => mb_strtolower($this->entityTypeManager
          ->getDefinition('team_app')
          ->getSingularLabel()),
      ]));
    }
  }
}