Skip to content
Snippets Groups Projects
Verified Commit 28723923 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3421001 by sorlov, mohit_aghera, larowlan, alexpott, smustgrave:...

Issue #3421001 by sorlov, mohit_aghera, larowlan, alexpott, smustgrave: Convert ViewsAccess plugin discovery to attributes
parent ab695b5c
No related branches found
No related tags found
No related merge requests found
......@@ -9,7 +9,9 @@
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\user\PermissionHandlerInterface;
use Drupal\views\Attribute\ViewsAccess;
use Drupal\views\Plugin\views\access\AccessPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\Route;
......@@ -18,13 +20,12 @@
* Access plugin that provides permission-based access control.
*
* @ingroup views_access_plugins
*
* @ViewsAccess(
* id = "perm",
* title = @Translation("Permission"),
* help = @Translation("Access will be granted to users with the specified permission string.")
* )
*/
#[ViewsAccess(
id: 'perm',
title: new TranslatableMarkup('Permission'),
help: new TranslatableMarkup('Access will be granted to users with the specified permission string.'),
)]
class Permission extends AccessPluginBase implements CacheableDependencyInterface {
use DeprecatedServicePropertyTrait;
......
......@@ -6,8 +6,10 @@
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\user\RoleInterface;
use Drupal\user\RoleStorageInterface;
use Drupal\views\Attribute\ViewsAccess;
use Drupal\views\Plugin\views\access\AccessPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\Route;
......@@ -17,13 +19,12 @@
* Access plugin that provides role-based access control.
*
* @ingroup views_access_plugins
*
* @ViewsAccess(
* id = "role",
* title = @Translation("Role"),
* help = @Translation("Access will be granted to users with any of the specified roles.")
* )
*/
#[ViewsAccess(
id: 'role',
title: new TranslatableMarkup('Role'),
help: new TranslatableMarkup('Access will be granted to users with any of the specified roles.'),
)]
class Role extends AccessPluginBase implements CacheableDependencyInterface {
/**
......
<?php
namespace Drupal\views\Attribute;
use Drupal\Component\Plugin\Attribute\Plugin;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Defines a views access plugins type attribute for plugin discovery.
*
* @see \Drupal\views\Plugin\views\access\AccessPluginBase
*
* @ingroup views_access_plugins
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
class ViewsAccess extends Plugin {
/**
* Constructs a ViewsAccess attribute.
*
* @param string $id
* The plugin ID.
* @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $title
* The plugin title used in the views UI.
* @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $short_title
* (optional) The short title used in the views UI.
* @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $help
* (optional) A short help string; this is displayed in the views UI.
* @param string[]|null $display_types
* (optional) The types of the display this plugin can be used with.
* For example the Feed display defines the type 'feed', so only rss style
* and row plugins can be used in the views UI.
* @param string[] $base
* (optional) The base tables on which this access plugin can be used.
* If no base table is specified the plugin can be used with all tables.
* @param bool $no_ui
* (optional) Whether the plugin should be not selectable in the UI.
* If set to TRUE, you can still use it via the API in config files.
* @param class-string|null $deriver
* (optional) The deriver class.
*/
public function __construct(
public readonly string $id,
public readonly TranslatableMarkup $title,
public readonly ?TranslatableMarkup $short_title = NULL,
public readonly ?TranslatableMarkup $help = NULL,
public readonly ?array $display_types = NULL,
public readonly array $base = [],
public readonly bool $no_ui = FALSE,
public readonly ?string $deriver = NULL
) {}
}
......@@ -3,19 +3,20 @@
namespace Drupal\views\Plugin\views\access;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsAccess;
use Symfony\Component\Routing\Route;
/**
* Access plugin that provides no access control at all.
*
* @ingroup views_access_plugins
*
* @ViewsAccess(
* id = "none",
* title = @Translation("Unrestricted"),
* help = @Translation("Will be available to all users.")
* )
*/
#[ViewsAccess(
id: 'none',
title: new TranslatableMarkup('Unrestricted'),
help: new TranslatableMarkup('Will be available to all users.'),
)]
class None extends AccessPluginBase {
/**
......
......@@ -6,19 +6,20 @@
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\State\StateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsAccess;
use Drupal\views\Plugin\views\access\AccessPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\Route;
/**
* Tests plugin that reports when cacheable metadata is being calculated.
*
* @ViewsAccess(
* id = "test_cacheable_metadata_access",
* title = @Translation("Cacheable metadata calculation test access plugin"),
* help = @Translation("Provides a test access plugin that reports when cacheable metadata is being calculated.")
* )
*/
#[ViewsAccess(
id: 'test_cacheable_metadata_access',
title: new TranslatableMarkup('Cacheable metadata calculation test access plugin'),
help: new TranslatableMarkup('Provides a test access plugin that reports when cacheable metadata is being calculated.'),
)]
class CacheableMetadataCalculationTest extends AccessPluginBase implements CacheableDependencyInterface {
/**
......
......@@ -3,18 +3,19 @@
namespace Drupal\views_test_data\Plugin\views\access;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsAccess;
use Drupal\views\Plugin\views\access\AccessPluginBase;
use Symfony\Component\Routing\Route;
/**
* Tests a static access plugin.
*
* @ViewsAccess(
* id = "test_static",
* title = @Translation("Static test access plugin"),
* help = @Translation("Provides a static test access plugin.")
* )
*/
#[ViewsAccess(
id: 'test_static',
title: new TranslatableMarkup('Static test access plugin'),
help: new TranslatableMarkup('Provides a static test access plugin.'),
)]
class StaticTest extends AccessPluginBase {
protected function defineOptions() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment