Version 1
[yaffs-website] / web / core / modules / views / src / Plugin / views / access / AccessPluginBase.php
1 <?php
2
3 namespace Drupal\views\Plugin\views\access;
4
5 use Drupal\Core\Session\AccountInterface;
6 use Drupal\views\Plugin\views\PluginBase;
7 use Symfony\Component\Routing\Route;
8
9 /**
10  * @defgroup views_access_plugins Views access plugins
11  * @{
12  * Plugins to handle access checking for views.
13  *
14  * Access plugins are responsible for controlling access to the view.
15  *
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.
20  *
21  * @ingroup views_plugins
22  * @see plugin_api
23  */
24
25 /**
26  * The base plugin to handle access control.
27  *
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.
30  *
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
33  * example:
34  * @Plugin(
35  *   id = "denyall",
36  *   title = @Translation("No Access"),
37  *   help = @Translation("Will not be accessible.")
38  * )
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.
43  *
44  * @see \Drupal\views\Plugin\ViewsPluginManager
45  */
46 abstract class AccessPluginBase extends PluginBase {
47
48   /**
49    * {@inheritdoc}
50    */
51   public function summaryTitle() {
52     return $this->t('Unknown');
53   }
54
55   /**
56    * Determine if the current user has access or not.
57    *
58    * @param \Drupal\Core\Session\AccountInterface $account
59    *   The user who wants to access this view.
60    *
61    * @return bool
62    *   Returns whether the user has access to the view.
63    */
64   abstract public function access(AccountInterface $account);
65
66   /**
67    * Allows access plugins to alter the route definition of a view.
68    *
69    * Likely the access plugin will add new requirements, so its custom access
70    * checker can be applied.
71    *
72    * @param \Symfony\Component\Routing\Route $route
73    *   The route to change.
74    */
75   abstract public function alterRouteDefinition(Route $route);
76
77 }
78
79 /**
80  * @}
81  */