You are here

public function SocialInviteSubscriber::notifyAboutPendingInvitations in Open Social 10.3.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_core/src/EventSubscriber/SocialInviteSubscriber.php \Drupal\social_core\EventSubscriber\SocialInviteSubscriber::notifyAboutPendingInvitations()
  2. 10.0.x modules/social_features/social_core/src/EventSubscriber/SocialInviteSubscriber.php \Drupal\social_core\EventSubscriber\SocialInviteSubscriber::notifyAboutPendingInvitations()
  3. 10.1.x modules/social_features/social_core/src/EventSubscriber/SocialInviteSubscriber.php \Drupal\social_core\EventSubscriber\SocialInviteSubscriber::notifyAboutPendingInvitations()
  4. 10.2.x modules/social_features/social_core/src/EventSubscriber/SocialInviteSubscriber.php \Drupal\social_core\EventSubscriber\SocialInviteSubscriber::notifyAboutPendingInvitations()

Notify user about Pending invitations.

Parameters

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

File

modules/social_features/social_core/src/EventSubscriber/SocialInviteSubscriber.php, line 96

Class

SocialInviteSubscriber
Social event subscriber.

Namespace

Drupal\social_core\EventSubscriber

Code

public function notifyAboutPendingInvitations(GetResponseEvent $event) {
  $data = $this->inviteService
    ->getInviteData();

  /** @var \Symfony\Component\HttpFoundation\Request $request */
  $request = $event
    ->getRequest();
  $request_path = $request
    ->getPathInfo();
  $route_name = $this->currentRoute
    ->getRouteName();
  $default_front = $this->siteSettings
    ->get('page.front');
  $frontpage_lu = $this->alternativeFrontpageSettings
    ->get('frontpage_for_authenticated_user') ?: '';

  // Either allow on paths.
  $paths_allowed = [
    $default_front,
    $frontpage_lu,
    '/',
  ];

  // Or allow on route names.
  $routes_allowed = [
    'social_core.homepage',
  ];

  // We want to show this message either on:
  // the default site front page
  // the front page set for authenticated users
  // or the stream being the social_core.homepage.
  if (in_array($request_path, $paths_allowed) || in_array($route_name, $routes_allowed)) {
    if (!empty($data['name']) && !empty($data['amount'])) {
      $replacement_url = [
        '@url' => Url::fromRoute($data['name'], [
          'user' => $this->currentUser
            ->id(),
        ])
          ->toString(),
      ];
      $message = $this
        ->formatPlural($data['amount'], 'You have 1 pending invite <a href="@url">visit your invite overview</a> to see it.', 'You have @count pending invites <a href="@url">visit your invite overview</a> to see them.', $replacement_url);
      $this->messenger
        ->addMessage($message, 'warning');
    }
  }
}