class SocialInviteSubscriber in Open Social 10.0.x
Same name and namespace in other branches
- 8.9 modules/social_features/social_core/src/EventSubscriber/SocialInviteSubscriber.php \Drupal\social_core\EventSubscriber\SocialInviteSubscriber
- 10.3.x modules/social_features/social_core/src/EventSubscriber/SocialInviteSubscriber.php \Drupal\social_core\EventSubscriber\SocialInviteSubscriber
- 10.1.x modules/social_features/social_core/src/EventSubscriber/SocialInviteSubscriber.php \Drupal\social_core\EventSubscriber\SocialInviteSubscriber
- 10.2.x modules/social_features/social_core/src/EventSubscriber/SocialInviteSubscriber.php \Drupal\social_core\EventSubscriber\SocialInviteSubscriber
Social event subscriber.
@package Drupal\social_core\SocialInviteSubscriber
Hierarchy
- class \Drupal\social_core\EventSubscriber\SocialInviteSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface uses StringTranslationTrait
Expanded class hierarchy of SocialInviteSubscriber
1 string reference to 'SocialInviteSubscriber'
- 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 SocialInviteSubscriber
- social_core.event_subscriber in modules/
social_features/ social_core/ social_core.services.yml - Drupal\social_core\EventSubscriber\SocialInviteSubscriber
File
- modules/
social_features/ social_core/ src/ EventSubscriber/ SocialInviteSubscriber.php, line 21
Namespace
Drupal\social_core\EventSubscriberView source
class SocialInviteSubscriber implements EventSubscriberInterface {
use StringTranslationTrait;
/**
* Group invitations loader.
*
* @var \Drupal\social_core\InviteService
*/
protected $inviteService;
/**
* The current user's account object.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* The Messenger service.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
/**
* The current route.
*
* @var \Drupal\Core\Routing\CurrentRouteMatch
*/
protected $currentRoute;
/**
* Protected var alternativeFrontpageSettings.
*
* @var \Drupal\Core\Config\ConfigFactory
*/
protected $alternativeFrontpageSettings;
/**
* Protected var siteSettings.
*
* @var \Drupal\Core\Config\ConfigFactory
*/
protected $siteSettings;
/**
* Constructs SocialInviteSubscriber.
*
* @param \Drupal\social_core\InviteService $inviteService
* Invitations loader service.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger service.
* @param \Drupal\Core\Routing\CurrentRouteMatch $route_match
* The current route.
* @param \Drupal\Core\Config\ConfigFactory $config_factory
* The config factory.
*/
public function __construct(InviteService $inviteService, AccountInterface $current_user, MessengerInterface $messenger, CurrentRouteMatch $route_match, ConfigFactory $config_factory) {
$this->inviteService = $inviteService;
$this->currentUser = $current_user;
$this->messenger = $messenger;
$this->currentRoute = $route_match;
$this->alternativeFrontpageSettings = $config_factory
->get('alternative_frontpage.settings');
$this->siteSettings = $config_factory
->get('system.site');
}
/**
* Notify user about Pending invitations.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* The GetResponseEvent to process.
*/
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');
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[KernelEvents::REQUEST][] = [
'notifyAboutPendingInvitations',
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SocialInviteSubscriber:: |
protected | property | Protected var alternativeFrontpageSettings. | |
SocialInviteSubscriber:: |
protected | property | The current route. | |
SocialInviteSubscriber:: |
protected | property | The current user's account object. | |
SocialInviteSubscriber:: |
protected | property | Group invitations loader. | |
SocialInviteSubscriber:: |
protected | property | The Messenger service. | |
SocialInviteSubscriber:: |
protected | property | Protected var siteSettings. | |
SocialInviteSubscriber:: |
public static | function | ||
SocialInviteSubscriber:: |
public | function | Notify user about Pending invitations. | |
SocialInviteSubscriber:: |
public | function | Constructs SocialInviteSubscriber. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |