message_thread-8.x-1.x-dev/src/Plugin/views/access/MessageThreadTabPermission.php
src/Plugin/views/access/MessageThreadTabPermission.php
<?php
namespace Drupal\message_thread\Plugin\views\access;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\views\Plugin\views\access\AccessPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\Route;
/**
* Access plugin that provides user and permission-based access control.
*
* @ingroup views_access_plugins
*
* @ViewsAccess(
* id = "message_thread",
* title = @Translation("Message Thread Tab"),
* help = @Translation("Access will be granted for user's own tab / users with bypass permissions.")
* )
*/
class MessageThreadTabPermission extends AccessPluginBase implements CacheableDependencyInterface {
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition
);
}
/**
* {@inheritdoc}
*/
public function access(AccountInterface $account) {
return _message_private_inbox_access();
}
/**
* {@inheritdoc}
*/
public function alterRouteDefinition(Route $route) {
$route->setRequirement('_custom_access', 'message_thread_tab_access_check');
}
/**
* {@inheritdoc}
*/
public function summaryTitle() {
return $this->t('Tab Permission');
}
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
return Cache::PERMANENT;
}
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
return ['user.permissions'];
}
/**
* {@inheritdoc}
*/
public function getCacheTags() {
return [];
}
}
