Problem/Motivation

On Drupal 11.2+, the Context module triggers the following deprecation:

Not supporting attribute discovery in Drupal\context\ContextReactionManager is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Provide an Attribute class and an Annotation class for BC. See https://www.drupal.org/node/3395582

Steps to reproduce

  1. Install and enable Context on Drupal 11.2 or later.
  2. Run a deprecation check, such as Upgrade Status.
  3. Observe the deprecation for Drupal\context\ContextReactionManager.

Proposed resolution

  • Add an attribute class for Context reaction plugins, with constructor parameters that map one-to-one to the existing ContextReaction annotation properties.
  • Update ContextReactionManager to pass the attribute class first and the existing annotation class second to DefaultPluginManager::__construct(). Retain the annotation class for backwards compatibility.

    Conceptually, the plugin manager constructor call should become:

    parent::__construct(
      'Plugin/ContextReaction',
      $namespaces,
      $module_handler,
      ContextReactionInterface::class,
      \Drupal\context\Attribute\ContextReaction::class,
      \Drupal\context\Annotation\ContextReaction::class,
    );
    
  • Convert Context reaction plugin definitions to use the new attribute class.

Remaining tasks

  • Add the ContextReaction attribute class.
  • Update ContextReactionManager to support attribute discovery with annotation fallback.
  • Convert Context reaction plugin definitions to attributes.
  • Add or update automated test coverage for plugin discovery.
  • Verify that the Drupal 11.2 deprecation is no longer reported.
  • Review
  • Merge

User interface changes

None.

API changes

A new Drupal\context\Attribute\ContextReaction attribute class will be introduced. The existing annotation class should remain available for backwards compatibility.

Data model changes

None.

Issue fork context-3623035

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

eelkeblok created an issue. See original summary.

eelkeblok’s picture

eelkeblok’s picture

Issue summary: View changes
eelkeblok’s picture

Issue summary: View changes

eelkeblok’s picture

Status: Active » Needs review

Should look something like this. Disclaimer: I've used AI to do the initial draft of the change.

I dropped support in all info.yml files for everything below 10.2, as attributes work since then (Codex was including conditional code checking for the existence of the Attribute class, which seems overkill). Note that the currently only supported minor version of Drupal 10 is 10.6.

Since 5.0 has been in RC for so long, this introduces a bit of a dilemma, because it would introduce a gap in the supported core versions. However, there are no suppored versions of Context 4 listed on the project page, and 5.0 is still in RC, I think we are good. Maybe the chance should even be taken to raise the minimimal core version to ^10.6.

Note that even if 4.x was still supported, "general wisdom" suggests dropping support for unsupported core versions does not require a new major version (https://www.drupal.org/docs/develop/managing-a-drupalorg-theme-module-or...).