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

Issue #3421003 by sorlov, quietone, pradhumanjain2311, smustgrave, larowlan,...

Issue #3421003 by sorlov, quietone, pradhumanjain2311, smustgrave, larowlan, alexpott: Convert ViewsArgumentDefault plugin discovery to attributes
parent 8f28c48d
Branches
Tags
No related merge requests found
Showing
with 100 additions and 46 deletions
......@@ -3,18 +3,19 @@
namespace Drupal\book\Plugin\views\argument_default;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\node\NodeStorageInterface;
use Drupal\node\Plugin\views\argument_default\Node;
use Drupal\views\Attribute\ViewsArgumentDefault;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Default argument plugin to get the current node's top level book.
*
* @ViewsArgumentDefault(
* id = "top_level_book",
* title = @Translation("Top Level Book from current node")
* )
*/
#[ViewsArgumentDefault(
id: 'top_level_book',
title: new TranslatableMarkup('Top Level Book from current node"'),
)]
class TopLevelBook extends Node {
/**
......
......@@ -5,18 +5,19 @@
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsArgumentDefault;
use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
use Drupal\node\NodeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Default argument plugin to extract a node.
*
* @ViewsArgumentDefault(
* id = "node",
* title = @Translation("Content ID from URL")
* )
*/
#[ViewsArgumentDefault(
id: 'node',
title: new TranslatableMarkup('Content ID from URL'),
)]
class Node extends ArgumentDefaultPluginBase implements CacheableDependencyInterface {
/**
......
......@@ -6,7 +6,9 @@
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\taxonomy\TermInterface;
use Drupal\views\Attribute\ViewsArgumentDefault;
use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
use Drupal\node\NodeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -14,12 +16,11 @@
/**
* Taxonomy tid default argument.
*
* @ViewsArgumentDefault(
* id = "taxonomy_tid",
* title = @Translation("Taxonomy term ID from URL")
* )
*/
#[ViewsArgumentDefault(
id: 'taxonomy_tid',
title: new TranslatableMarkup('Taxonomy term ID from URL'),
)]
class Tid extends ArgumentDefaultPluginBase implements CacheableDependencyInterface {
/**
......
......@@ -4,18 +4,19 @@
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsArgumentDefault;
use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
/**
* Default argument plugin to extract the current user.
*
* This plugin actually has no options so it does not need to do a great deal.
*
* @ViewsArgumentDefault(
* id = "current_user",
* title = @Translation("User ID from logged in user")
* )
*/
#[ViewsArgumentDefault(
id: 'current_user',
title: new TranslatableMarkup('User ID from logged in user'),
)]
class CurrentUser extends ArgumentDefaultPluginBase implements CacheableDependencyInterface {
/**
......
......@@ -6,6 +6,8 @@
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsArgumentDefault;
use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\user\UserInterface;
......@@ -13,12 +15,11 @@
/**
* Default argument plugin to extract a user from request.
*
* @ViewsArgumentDefault(
* id = "user",
* title = @Translation("User ID from route context")
* )
*/
#[ViewsArgumentDefault(
id: 'user',
title: new TranslatableMarkup('User ID from route context"'),
)]
class User extends ArgumentDefaultPluginBase implements CacheableDependencyInterface {
/**
......
<?php
declare(strict_types=1);
namespace Drupal\views\Attribute;
use Drupal\Component\Plugin\Attribute\Plugin;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Defines a ViewsArgument attribute for plugin discovery.
*
* @see \Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase
*
* @ingroup views_argument_default_plugins
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
class ViewsArgumentDefault extends Plugin {
/**
* Constructs a ViewsArgument 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 bool $no_ui
* (optional) Whether the plugin should be not selectable in the UI. If it's
* 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 = NULL,
public readonly ?TranslatableMarkup $short_title = NULL,
public readonly bool $no_ui = FALSE,
public readonly ?string $deriver = NULL
) {}
}
......@@ -17,8 +17,8 @@
*
* Argument default plugins extend
* \Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase. They
* must be annotated with \Drupal\views\Annotation\ViewsArgumentDefault
* annotation, and they must be in namespace directory
* must be attributed with \Drupal\views\Attribute\ViewsArgumentDefault
* attribute, and they must be in namespace directory
* Plugin\views\argument_default.
*
* @ingroup views_plugins
......
......@@ -5,17 +5,19 @@
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsArgumentDefault;
/**
* The fixed argument default handler.
*
* @ingroup views_argument_default_plugins
*
* @ViewsArgumentDefault(
* id = "fixed",
* title = @Translation("Fixed")
* )
*/
#[ViewsArgumentDefault(
id: 'fixed',
title: new TranslatableMarkup('Fixed'),
)]
class Fixed extends ArgumentDefaultPluginBase implements CacheableDependencyInterface {
/**
......
......@@ -6,17 +6,18 @@
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsArgumentDefault;
/**
* A query parameter argument default handler.
*
* @ingroup views_argument_default_plugins
*
* @ViewsArgumentDefault(
* id = "query_parameter",
* title = @Translation("Query parameter")
* )
*/
#[ViewsArgumentDefault(
id: 'query_parameter',
title: new TranslatableMarkup('Query parameter'),
)]
class QueryParameter extends ArgumentDefaultPluginBase implements CacheableDependencyInterface {
/**
......
......@@ -6,19 +6,21 @@
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Path\CurrentPathStack;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\path_alias\AliasManagerInterface;
use Drupal\views\Attribute\ViewsArgumentDefault;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Default argument plugin to use the raw value from the URL.
*
* @ingroup views_argument_default_plugins
*
* @ViewsArgumentDefault(
* id = "raw",
* title = @Translation("Raw value from URL")
* )
*/
#[ViewsArgumentDefault(
id: 'raw',
title: new TranslatableMarkup('Raw value from URL'),
)]
class Raw extends ArgumentDefaultPluginBase implements CacheableDependencyInterface {
/**
......
......@@ -2,16 +2,17 @@
namespace Drupal\views_test_data\Plugin\views\argument_default;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Attribute\ViewsArgumentDefault;
use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
/**
* Defines an argument default test plugin.
*
* @ViewsArgumentDefault(
* id = "argument_default_test",
* title = @Translation("Argument default test")
* )
*/
#[ViewsArgumentDefault(
id: 'argument_default_test',
title: new TranslatableMarkup('Argument default test'),
)]
class ArgumentDefaultTest extends ArgumentDefaultPluginBase {
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment