You are here

public function InviteService::getInviteData in Open Social 10.3.x

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

The Invite data for redirect.

Parameters

string $specific: Can be either name or amount.

Return value

array|string Array containing the route name and or invite amount.

File

modules/social_features/social_core/src/InviteService.php, line 60

Class

InviteService
Class InviteService.

Namespace

Drupal\social_core

Code

public function getInviteData($specific = '') {

  // Empty by default, we will decorate this in our custom extensions.
  // these can decide on priority what the baseRoute should be.
  $route = [
    'amount' => 0,
    'name' => '',
  ];

  // Default routes. These will be overridden when there are
  // invites available, but we need to determine defaults so we can
  // render the Invite accountheader block link pointing to the overview
  // that is available by the plugins.
  // @todo make this more pretty and generic.
  if ($this->moduleHandler
    ->moduleExists('social_event_invite')) {
    $route['name'] = 'view.user_event_invites.page_user_event_invites';
  }
  if ($this->moduleHandler
    ->moduleExists('social_group_invite')) {
    $route['name'] = 'view.social_group_user_invitations.page_1';
  }

  // If module is enabled and it has invites, lets add the route.
  if ($this->moduleHandler
    ->moduleExists('social_event_invite')) {
    if (\Drupal::hasService('social_event.status_helper')) {

      /** @var \Drupal\social_event\EventEnrollmentStatusHelper $eventHelper */
      $eventHelper = \Drupal::service('social_event.status_helper');
      $event_invites = $eventHelper
        ->getAllUserEventEnrollments($this->currentUser
        ->id());
      if (NULL !== $event_invites && $event_invites > 0) {
        $route['amount'] += count($event_invites);

        // Override the route, because we have available invites!
        $route['name'] = 'view.user_event_invites.page_user_event_invites';
      }
    }
  }
  if ($this->moduleHandler
    ->moduleExists('social_group_invite')) {
    if (\Drupal::hasService('ginvite.invitation_loader')) {

      /** @var \Drupal\ginvite\GroupInvitationLoader $loader */
      $loader = \Drupal::service('ginvite.invitation_loader');
      $group_invites = count($loader
        ->loadByUser());
      if (NULL !== $group_invites && $group_invites > 0) {
        $route['amount'] += $group_invites;

        // Override the route, because we have available invites!
        $route['name'] = 'view.social_group_user_invitations.page_1';
      }
    }
  }

  // Return specific data.
  if ($specific === 'name') {
    return $route['name'];
  }
  if ($specific === 'amount') {
    return $route['amount'];
  }
  return $route;
}