EventInviteLocalTask.php in Open Social 10.2.x
File
modules/social_features/social_event/modules/social_event_invite/src/Plugin/Menu/LocalTask/EventInviteLocalTask.php
View source
<?php
namespace Drupal\social_event_invite\Plugin\Menu\LocalTask;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Menu\LocalTaskDefault;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\user\UserInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
class EventInviteLocalTask extends LocalTaskDefault implements ContainerFactoryPluginInterface {
use StringTranslationTrait;
protected $routeMatch;
public function __construct(array $configuration, $plugin_id, array $plugin_definition, RouteMatchInterface $routeMatch) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->routeMatch = $routeMatch;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('current_route_match'));
}
public function getTitle(Request $request = NULL) {
$enrollments = \Drupal::service('social_event.status_helper');
if ($enrollments
->getAllUserEventEnrollments(NULL)) {
return $this
->t('Event invites (@count)', [
'@count' => count($enrollments
->getAllUserEventEnrollments(NULL)),
]);
}
return $this
->t('Event invites');
}
public function getCacheTags() {
$tags = [];
$user = $this->routeMatch
->getParameter('user');
if ($user instanceof UserInterface) {
$tags[] = 'event_content_list:entity:' . $user
->id();
}
if (is_string($user)) {
$tags[] = 'event_content_list:entity:' . $user;
}
return Cache::mergeTags(parent::getCacheTags(), $tags);
}
}