class InviteService in Open Social 10.0.x
Same name and namespace in other branches
- 8.9 modules/social_features/social_core/src/InviteService.php \Drupal\social_core\InviteService
- 10.3.x modules/social_features/social_core/src/InviteService.php \Drupal\social_core\InviteService
- 10.1.x modules/social_features/social_core/src/InviteService.php \Drupal\social_core\InviteService
- 10.2.x modules/social_features/social_core/src/InviteService.php \Drupal\social_core\InviteService
Class InviteService.
Hierarchy
- class \Drupal\social_core\InviteService
Expanded class hierarchy of InviteService
1 file declares its use of InviteService
- SocialInviteSubscriber.php in modules/
social_features/ social_core/ src/ EventSubscriber/ SocialInviteSubscriber.php
1 string reference to 'InviteService'
- social_core.services.yml in modules/
social_features/ social_core/ social_core.services.yml - modules/social_features/social_core/social_core.services.yml
1 service uses InviteService
- social_core.invite in modules/
social_features/ social_core/ social_core.services.yml - Drupal\social_core\InviteService
File
- modules/
social_features/ social_core/ src/ InviteService.php, line 12
Namespace
Drupal\social_coreView source
class InviteService {
/**
* Request stack object.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $currentUser;
/**
* InviteService constructor.
*
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* Request.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
* ModuleHandler.
* @param \Drupal\Core\Session\AccountProxyInterface $currentUser
* The current user.
*/
public function __construct(RequestStack $request_stack, ModuleHandlerInterface $moduleHandler, AccountProxyInterface $currentUser) {
$this->requestStack = $request_stack;
$this->moduleHandler = $moduleHandler;
$this->currentUser = $currentUser;
}
/**
* The Invite data for redirect.
*
* @param string $specific
* Can be either name or amount.
*
* @return array|string
* Array containing the route name and or invite amount.
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
InviteService:: |
protected | property | The current user. | |
InviteService:: |
protected | property | The module handler. | |
InviteService:: |
protected | property | Request stack object. | |
InviteService:: |
public | function | The Invite data for redirect. | |
InviteService:: |
public | function | InviteService constructor. |