3 namespace Drupal\views\Plugin\views\access;
5 use Drupal\Core\Session\AccountInterface;
6 use Drupal\views\Plugin\views\PluginBase;
7 use Symfony\Component\Routing\Route;
10 * @defgroup views_access_plugins Views access plugins
12 * Plugins to handle access checking for views.
14 * Access plugins are responsible for controlling access to the view.
16 * Access plugins extend \Drupal\views\Plugin\views\access\AccessPluginBase,
17 * implementing the access() and alterRouteDefinition() methods. They must be
18 * annotated with \Drupal\views\Annotation\ViewsAccess annotation, and they
19 * must be in namespace directory Plugin\views\access.
21 * @ingroup views_plugins
26 * The base plugin to handle access control.
28 * Access plugins are responsible for controlling a user's access to the view.
29 * Views includes plugins for checking user roles and individual permissions.
31 * To define an access control plugin, extend this base class. Your access
32 * plugin should have an annotation that includes the plugin's metadata, for
36 * title = @Translation("No Access"),
37 * help = @Translation("Will not be accessible.")
39 * The definition should include the following keys:
40 * - id: The unique identifier of your access plugin.
41 * - title: The human-readable name for your access plugin.
42 * - help: A short help message for your plugin.
44 * @see \Drupal\views\Plugin\ViewsPluginManager
46 abstract class AccessPluginBase extends PluginBase {
51 public function summaryTitle() {
52 return $this->t('Unknown');
56 * Determine if the current user has access or not.
58 * @param \Drupal\Core\Session\AccountInterface $account
59 * The user who wants to access this view.
62 * Returns whether the user has access to the view.
64 abstract public function access(AccountInterface $account);
67 * Allows access plugins to alter the route definition of a view.
69 * Likely the access plugin will add new requirements, so its custom access
70 * checker can be applied.
72 * @param \Symfony\Component\Routing\Route $route
73 * The route to change.
75 abstract public function alterRouteDefinition(Route $route);