GroupInviteLocalTask.php in Open Social 10.1.x
File
modules/social_features/social_group/modules/social_group_invite/src/Plugin/Menu/LocalTask/GroupInviteLocalTask.php
View source
<?php
namespace Drupal\social_group_invite\Plugin\Menu\LocalTask;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\ginvite\GroupInvitationLoaderInterface;
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 GroupInviteLocalTask extends LocalTaskDefault implements ContainerFactoryPluginInterface {
use StringTranslationTrait;
protected $routeMatch;
protected $invitationLoader;
public function __construct(array $configuration, $plugin_id, array $plugin_definition, RouteMatchInterface $routeMatch, GroupInvitationLoaderInterface $invitationLoader) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->routeMatch = $routeMatch;
$this->invitationLoader = $invitationLoader;
}
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'), $container
->get('ginvite.invitation_loader'));
}
public function getTitle(Request $request = NULL) {
if ($this->invitationLoader
->loadByUser()) {
return $this
->t('Group invites (@count)', [
'@count' => count($this->invitationLoader
->loadByUser()),
]);
}
return $this
->t('Group invites');
}
public function getCacheTags() {
$tags = [];
$user = $this->routeMatch
->getParameter('user');
if ($user instanceof UserInterface) {
$tags[] = 'group_content_list:entity:' . $user
->id();
$tags[] = 'group_content_list:plugin:group_invitation:entity:' . $user
->id();
}
if (is_string($user)) {
$tags[] = 'group_content_list:entity:' . $user;
$tags[] = 'group_content_list:plugin:group_invitation:entity:' . $user;
}
return Cache::mergeTags(parent::getCacheTags(), $tags);
}
}