Skip to content
Snippets Groups Projects
Commit eb61f11b authored by catch's avatar catch
Browse files

Issue #3420986 by kim.pepper, sorlov, larowlan, mstrelan: Convert Condition...

Issue #3420986 by kim.pepper, sorlov, larowlan, mstrelan: Convert Condition plugin discovery to attributes
parent 4ae7f854
No related branches found
No related tags found
31 merge requests!11131[10.4.x-only-DO-NOT-MERGE]: Issue ##2842525 Ajax attached to Views exposed filter form does not trigger callbacks,!9470[10.3.x-only-DO-NOT-MERGE]: #3331771 Fix file_get_contents(): Passing null to parameter,!8540Issue #3457061: Bootstrap Modal dialog Not closing after 10.3.0 Update,!8528Issue #3456871 by Tim Bozeman: Support NULL services,!8373Issue #3427374 by danflanagan8, Vighneshh: taxonomy_tid ViewsArgumentDefault...,!7526Expose roles in response,!7352Draft: Resolve #3203489 "Set filename as",!3878Removed unused condition head title for views,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3668Resolve #3347842 "Deprecate the trusted",!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2794Issue #3100732: Allow specifying `meta` data on JSON:API objects,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #108230 canceled
Pipeline: drupal

#108231

    Showing
    with 176 additions and 74 deletions
    <?php
    declare(strict_types=1);
    namespace Drupal\Core\Condition\Attribute;
    use Drupal\Component\Plugin\Attribute\Plugin;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    /**
    * Defines a condition plugin attribute.
    *
    * Condition plugins provide generalized conditions for use in other
    * operations, such as conditional block placement.
    *
    * Plugin Namespace: Plugin\Condition
    *
    * For a working example, see \Drupal\user\Plugin\Condition\UserRole.
    *
    * @see \Drupal\Core\Condition\ConditionManager
    * @see \Drupal\Core\Condition\ConditionInterface
    * @see \Drupal\Core\Condition\ConditionPluginBase
    * @see block_api
    *
    * @ingroup plugin_api
    */
    #[\Attribute(\Attribute::TARGET_CLASS)]
    class Condition extends Plugin {
    /**
    * Constructs a Condition attribute.
    *
    * @param string $id
    * The plugin ID.
    * @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $label
    * (optional) The human-readable name of the condition.
    * @param string|null $module
    * (optional) The name of the module providing the type.
    * @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $category
    * (optional) The category under which the condition should be listed in the
    * UI.
    * @param array $context_definitions
    * (optional) An array of context definitions describing the context used by
    * the plugin.
    * @param class-string|null $deriver
    * (optional) The deriver class.
    */
    public function __construct(
    public readonly string $id,
    public readonly ?TranslatableMarkup $label = NULL,
    public readonly ?string $module = NULL,
    public readonly ?TranslatableMarkup $category = NULL,
    public readonly array $context_definitions = [],
    public readonly ?string $deriver = NULL,
    ) {}
    }
    ...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
    * @see \Drupal\Core\Executable\ExecutableInterface * @see \Drupal\Core\Executable\ExecutableInterface
    * @see \Drupal\Core\Condition\ConditionManager * @see \Drupal\Core\Condition\ConditionManager
    * @see \Drupal\Core\Condition\Annotation\Condition * @see \Drupal\Core\Condition\Annotation\Condition
    * @see \Drupal\Core\Condition\Attribute\Condition
    * @see \Drupal\Core\Condition\ConditionPluginBase * @see \Drupal\Core\Condition\ConditionPluginBase
    * *
    * @ingroup plugin_api * @ingroup plugin_api
    ......
    ...@@ -4,9 +4,10 @@ ...@@ -4,9 +4,10 @@
    use Drupal\Component\Plugin\CategorizingPluginManagerInterface; use Drupal\Component\Plugin\CategorizingPluginManagerInterface;
    use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Cache\CacheBackendInterface;
    use Drupal\Core\Condition\Attribute\Condition;
    use Drupal\Core\Executable\ExecutableException; use Drupal\Core\Executable\ExecutableException;
    use Drupal\Core\Executable\ExecutableManagerInterface;
    use Drupal\Core\Executable\ExecutableInterface; use Drupal\Core\Executable\ExecutableInterface;
    use Drupal\Core\Executable\ExecutableManagerInterface;
    use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ModuleHandlerInterface;
    use Drupal\Core\Plugin\CategorizingPluginManagerTrait; use Drupal\Core\Plugin\CategorizingPluginManagerTrait;
    use Drupal\Core\Plugin\DefaultPluginManager; use Drupal\Core\Plugin\DefaultPluginManager;
    ...@@ -16,7 +17,7 @@ ...@@ -16,7 +17,7 @@
    /** /**
    * A plugin manager for condition plugins. * A plugin manager for condition plugins.
    * *
    * @see \Drupal\Core\Condition\Annotation\Condition * @see \Drupal\Core\Condition\Attribute\Condition
    * @see \Drupal\Core\Condition\ConditionInterface * @see \Drupal\Core\Condition\ConditionInterface
    * @see \Drupal\Core\Condition\ConditionPluginBase * @see \Drupal\Core\Condition\ConditionPluginBase
    * *
    ...@@ -42,7 +43,14 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac ...@@ -42,7 +43,14 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac
    $this->alterInfo('condition_info'); $this->alterInfo('condition_info');
    $this->setCacheBackend($cache_backend, 'condition_plugins'); $this->setCacheBackend($cache_backend, 'condition_plugins');
    parent::__construct('Plugin/Condition', $namespaces, $module_handler, 'Drupal\Core\Condition\ConditionInterface', 'Drupal\Core\Condition\Annotation\Condition'); parent::__construct(
    'Plugin/Condition',
    $namespaces,
    $module_handler,
    ConditionInterface::class,
    Condition::class,
    'Drupal\Core\Condition\Annotation\Condition'
    );
    } }
    /** /**
    ......
    ...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
    * Provides a basis for fulfilling contexts for condition plugins. * Provides a basis for fulfilling contexts for condition plugins.
    * *
    * @see \Drupal\Core\Condition\Annotation\Condition * @see \Drupal\Core\Condition\Annotation\Condition
    * @see \Drupal\Core\Condition\Attribute\Condition
    * @see \Drupal\Core\Condition\ConditionInterface * @see \Drupal\Core\Condition\ConditionInterface
    * @see \Drupal\Core\Condition\ConditionManager * @see \Drupal\Core\Condition\ConditionManager
    * *
    ......
    ...@@ -2,20 +2,21 @@ ...@@ -2,20 +2,21 @@
    namespace Drupal\Core\Entity\Plugin\Condition; namespace Drupal\Core\Entity\Plugin\Condition;
    use Drupal\Core\Condition\Attribute\Condition;
    use Drupal\Core\Condition\ConditionPluginBase; use Drupal\Core\Condition\ConditionPluginBase;
    use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
    use Drupal\Core\Entity\Plugin\Condition\Deriver\EntityBundle as EntityBundleDeriver;
    use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
    use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
    use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
    /** /**
    * Provides the 'Entity Bundle' condition. * Provides the 'Entity Bundle' condition.
    *
    * @Condition(
    * id = "entity_bundle",
    * deriver = "\Drupal\Core\Entity\Plugin\Condition\Deriver\EntityBundle",
    * )
    */ */
    #[Condition(
    id: "entity_bundle",
    deriver: EntityBundleDeriver::class,
    )]
    class EntityBundle extends ConditionPluginBase implements ContainerFactoryPluginInterface { class EntityBundle extends ConditionPluginBase implements ContainerFactoryPluginInterface {
    /** /**
    ......
    ...@@ -2,16 +2,17 @@ ...@@ -2,16 +2,17 @@
    namespace Drupal\block_test\Plugin\Condition; namespace Drupal\block_test\Plugin\Condition;
    use Drupal\Core\Condition\Attribute\Condition;
    use Drupal\Core\Condition\ConditionPluginBase; use Drupal\Core\Condition\ConditionPluginBase;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    /** /**
    * Provides a 'baloney_spam' condition. * Provides a 'baloney_spam' condition.
    *
    * @Condition(
    * id = "baloney_spam",
    * label = @Translation("Baloney spam"),
    * )
    */ */
    #[Condition(
    id: "baloney_spam",
    label: new TranslatableMarkup("Baloney spam"),
    )]
    class BaloneySpam extends ConditionPluginBase { class BaloneySpam extends ConditionPluginBase {
    /** /**
    ......
    ...@@ -2,16 +2,17 @@ ...@@ -2,16 +2,17 @@
    namespace Drupal\block_test\Plugin\Condition; namespace Drupal\block_test\Plugin\Condition;
    use Drupal\Core\Condition\Attribute\Condition;
    use Drupal\Core\Condition\ConditionPluginBase; use Drupal\Core\Condition\ConditionPluginBase;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    /** /**
    * Provides a 'missing_schema' condition. * Provides a 'missing_schema' condition.
    *
    * @Condition(
    * id = "missing_schema",
    * label = @Translation("Missing schema"),
    * )
    */ */
    #[Condition(
    id: "missing_schema",
    label: new TranslatableMarkup("Missing schema"),
    )]
    class MissingSchema extends ConditionPluginBase { class MissingSchema extends ConditionPluginBase {
    /** /**
    ......
    ...@@ -2,24 +2,29 @@ ...@@ -2,24 +2,29 @@
    namespace Drupal\language\Plugin\Condition; namespace Drupal\language\Plugin\Condition;
    use Drupal\Core\Condition\Attribute\Condition;
    use Drupal\Core\Condition\ConditionPluginBase; use Drupal\Core\Condition\ConditionPluginBase;
    use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
    use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
    use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Language\LanguageManagerInterface;
    use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
    use Drupal\Core\Plugin\Context\ContextDefinition;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
    /** /**
    * Provides a 'Language' condition. * Provides a 'Language' condition.
    *
    * @Condition(
    * id = "language",
    * label = @Translation("Language"),
    * context_definitions = {
    * "language" = @ContextDefinition("language", label = @Translation("Language"))
    * }
    * )
    */ */
    #[Condition(
    id: "language",
    label: new TranslatableMarkup("Language"),
    context_definitions: [
    "language" => new ContextDefinition(
    data_type: "language",
    label: new TranslatableMarkup("Language"),
    ),
    ]
    )]
    class Language extends ConditionPluginBase implements ContainerFactoryPluginInterface { class Language extends ConditionPluginBase implements ContainerFactoryPluginInterface {
    /** /**
    ......
    ...@@ -2,21 +2,22 @@ ...@@ -2,21 +2,22 @@
    namespace Drupal\system\Plugin\Condition; namespace Drupal\system\Plugin\Condition;
    use Drupal\Core\Condition\Attribute\Condition;
    use Drupal\Core\Condition\ConditionPluginBase; use Drupal\Core\Condition\ConditionPluginBase;
    use Drupal\Core\Extension\ThemeHandlerInterface; use Drupal\Core\Extension\ThemeHandlerInterface;
    use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
    use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    use Drupal\Core\Theme\ThemeManagerInterface; use Drupal\Core\Theme\ThemeManagerInterface;
    use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
    /** /**
    * Provides a 'Current Theme' condition. * Provides a 'Current Theme' condition.
    *
    * @Condition(
    * id = "current_theme",
    * label = @Translation("Current Theme"),
    * )
    */ */
    #[Condition(
    id: "current_theme",
    label: new TranslatableMarkup("Current Theme"),
    )]
    class CurrentThemeCondition extends ConditionPluginBase implements ContainerFactoryPluginInterface { class CurrentThemeCondition extends ConditionPluginBase implements ContainerFactoryPluginInterface {
    /** /**
    ......
    ...@@ -2,23 +2,24 @@ ...@@ -2,23 +2,24 @@
    namespace Drupal\system\Plugin\Condition; namespace Drupal\system\Plugin\Condition;
    use Drupal\Core\Condition\Attribute\Condition;
    use Drupal\Core\Condition\ConditionPluginBase; use Drupal\Core\Condition\ConditionPluginBase;
    use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
    use Drupal\Core\Path\CurrentPathStack; use Drupal\Core\Path\CurrentPathStack;
    use Drupal\Core\Path\PathMatcherInterface; use Drupal\Core\Path\PathMatcherInterface;
    use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    use Drupal\path_alias\AliasManagerInterface; use Drupal\path_alias\AliasManagerInterface;
    use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
    use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
    /** /**
    * Provides a 'Request Path' condition. * Provides a 'Request Path' condition.
    *
    * @Condition(
    * id = "request_path",
    * label = @Translation("Request Path"),
    * )
    */ */
    #[Condition(
    id: "request_path",
    label: new TranslatableMarkup("Request Path"),
    )]
    class RequestPath extends ConditionPluginBase implements ContainerFactoryPluginInterface { class RequestPath extends ConditionPluginBase implements ContainerFactoryPluginInterface {
    /** /**
    ......
    ...@@ -4,10 +4,12 @@ ...@@ -4,10 +4,12 @@
    namespace Drupal\system\Plugin\Condition; namespace Drupal\system\Plugin\Condition;
    use Drupal\Core\Condition\Attribute\Condition;
    use Drupal\Core\Condition\ConditionPluginBase; use Drupal\Core\Condition\ConditionPluginBase;
    use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
    use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
    use Drupal\Core\StringTranslation\PluralTranslatableMarkup; use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
    use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
    use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
    ...@@ -15,12 +17,11 @@ ...@@ -15,12 +17,11 @@
    /** /**
    * Provides a 'Response status' condition. * Provides a 'Response status' condition.
    *
    * @Condition(
    * id = "response_status",
    * label = @Translation("Response status"),
    * )
    */ */
    #[Condition(
    id: "response_status",
    label: new TranslatableMarkup("Response status"),
    )]
    class ResponseStatus extends ConditionPluginBase implements ContainerFactoryPluginInterface { class ResponseStatus extends ConditionPluginBase implements ContainerFactoryPluginInterface {
    /** /**
    ......
    ...@@ -2,20 +2,28 @@ ...@@ -2,20 +2,28 @@
    namespace Drupal\condition_test\Plugin\Condition; namespace Drupal\condition_test\Plugin\Condition;
    use Drupal\Core\Condition\Attribute\Condition;
    use Drupal\Core\Condition\ConditionPluginBase; use Drupal\Core\Condition\ConditionPluginBase;
    use Drupal\Core\Plugin\Context\EntityContextDefinition;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    /** /**
    * Provides a condition that requires two users. * Provides a condition that requires two users.
    *
    * @Condition(
    * id = "condition_test_dual_user",
    * label = @Translation("Dual user"),
    * context_definitions = {
    * "user1" = @ContextDefinition("entity:user", label = @Translation("User 1")),
    * "user2" = @ContextDefinition("entity:user", label = @Translation("User 2"))
    * }
    * )
    */ */
    #[Condition(
    id: "condition_test_dual_user",
    label: new TranslatableMarkup("Dual user"),
    context_definitions: [
    "user1" => new EntityContextDefinition(
    data_type: "entity:user",
    label: new TranslatableMarkup("User 1"),
    ),
    "user2" => new EntityContextDefinition(
    data_type: "entity:user",
    label: new TranslatableMarkup("User 2"),
    ),
    ]
    )]
    class ConditionTestDualUser extends ConditionPluginBase { class ConditionTestDualUser extends ConditionPluginBase {
    /** /**
    ......
    ...@@ -2,19 +2,24 @@ ...@@ -2,19 +2,24 @@
    namespace Drupal\condition_test\Plugin\Condition; namespace Drupal\condition_test\Plugin\Condition;
    use Drupal\Core\Condition\Attribute\Condition;
    use Drupal\Core\Condition\ConditionPluginBase; use Drupal\Core\Condition\ConditionPluginBase;
    use Drupal\Core\Plugin\Context\ContextDefinition;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    /** /**
    * Provides a condition that has a no existing context. * Provides a condition that has a no existing context.
    *
    * @Condition(
    * id = "condition_test_no_existing_type",
    * label = @Translation("No existing type"),
    * context_definitions = {
    * "no_existing_type" = @ContextDefinition("no_existing_type", label = @Translation("No existing type")),
    * }
    * )
    */ */
    #[Condition(
    id: "condition_test_no_existing_type",
    label: new TranslatableMarkup("No existing type"),
    context_definitions: [
    "no_existing_type" => new ContextDefinition(
    data_type: "no_existing_type",
    label: new TranslatableMarkup("No existing type"),
    ),
    ]
    )]
    class ConditionTestNoExistingType extends ConditionPluginBase { class ConditionTestNoExistingType extends ConditionPluginBase {
    /** /**
    ......
    ...@@ -2,22 +2,28 @@ ...@@ -2,22 +2,28 @@
    namespace Drupal\condition_test\Plugin\Condition; namespace Drupal\condition_test\Plugin\Condition;
    use Drupal\Core\Condition\Attribute\Condition;
    use Drupal\Core\Condition\ConditionPluginBase; use Drupal\Core\Condition\ConditionPluginBase;
    use Drupal\Core\Plugin\Context\EntityContextDefinition;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    /** /**
    * Provides a condition with an optional node context. * Provides a condition with an optional node context.
    * *
    * The context type entity:node is used since that would allow to also use this * The context type entity:node is used since that would allow to also use this
    * for web tests with the node route context. * for web tests with the node route context.
    *
    * @Condition(
    * id = "condition_test_optional_context",
    * label = @Translation("Optional context"),
    * context_definitions = {
    * "node" = @ContextDefinition("entity:node", label = @Translation("Node"), required = FALSE),
    * }
    * )
    */ */
    #[Condition(
    id: "condition_test_optional_context",
    label: new TranslatableMarkup("Optional context"),
    context_definitions: [
    "node" => new EntityContextDefinition(
    data_type: "entity:node",
    label: new TranslatableMarkup("Node"),
    required: FALSE,
    ),
    ]
    )]
    class OptionalContextCondition extends ConditionPluginBase { class OptionalContextCondition extends ConditionPluginBase {
    /** /**
    ......
    ...@@ -3,22 +3,27 @@ ...@@ -3,22 +3,27 @@
    namespace Drupal\user\Plugin\Condition; namespace Drupal\user\Plugin\Condition;
    use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Html;
    use Drupal\Core\Condition\Attribute\Condition;
    use Drupal\Core\Condition\ConditionPluginBase; use Drupal\Core\Condition\ConditionPluginBase;
    use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
    use Drupal\Core\Plugin\Context\EntityContextDefinition;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    use Drupal\user\Entity\Role; use Drupal\user\Entity\Role;
    use Drupal\user\RoleInterface; use Drupal\user\RoleInterface;
    /** /**
    * Provides a 'User Role' condition. * Provides a 'User Role' condition.
    *
    * @Condition(
    * id = "user_role",
    * label = @Translation("User Role"),
    * context_definitions = {
    * "user" = @ContextDefinition("entity:user", label = @Translation("User"))
    * }
    * )
    */ */
    #[Condition(
    id: "user_role",
    label: new TranslatableMarkup("User Role"),
    context_definitions: [
    "user" => new EntityContextDefinition(
    data_type: "entity:user",
    label: new TranslatableMarkup("User"),
    ),
    ],
    )]
    class UserRole extends ConditionPluginBase { class UserRole extends ConditionPluginBase {
    /** /**
    ......
    • catch @catch

      mentioned in commit 20ca5cce

      ·

      mentioned in commit 20ca5cce

      Toggle commit list
    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