Problem/Motivation

As per the change record Plugin implementations should use PHP attributes instead of annotations, Drupal 11 requires plugins to use PHP 8 attributes instead of
doctrine annotations.

The FlagViewsRelationship plugin in src/Plugin/views/relationship/FlagViewsRelationship.php still uses the old annotation format:

/**                                                                                                                                                                                                            
   * Provides a views relationship to select flag content by a flag.                                                                                                                                                        
   *                                                                                                                                                                                                                        
   * @ViewsRelationship("flag_relationship")                                                                                                                                                                                
   */                                                                                                                                                                                                                       
  class FlagViewsRelationship extends RelationshipPluginBase implements CacheableDependencyInterface {                                                                                                                      
  

This causes the relationship to be marked as "Broken" in Views when running on Drupal 11.3.x, resulting in errors like:

  • Warning: Undefined array key "base" in Drupal\views\Plugin\views\query\QueryPluginBase->getEntityTableInfo()
  • InvalidArgumentException: A valid cache entry key is required

Steps to reproduce

  1. Install Flag 5.0.3 on Drupal 11.x
  2. Create a view with a Flag relationship
  3. The relationship appears as "Broken/missing handler"

Proposed resolution

Convert the annotation to PHP 8 attribute format:

use Drupal\views\Attribute\ViewsRelationship;                                                                                                                                                                  
                                                                                                                                                                                                                            
  /**                                                                                                                                                                                                                       
   * Provides a views relationship to select flag content by a flag.                                                                                                                                                        
   */                                                                                                                                                                                                                       
  #[ViewsRelationship("flag_relationship")]                                                                                                                                                                                 
  class FlagViewsRelationship extends RelationshipPluginBase implements CacheableDependencyInterface {                                                                                                                      
  

Remaining tasks

  • Review if other plugins in the Flag module also need conversion to attributes
  • Create patch
  • Add test coverage

User interface changes

None

API changes

None

Data model changes

None

CommentFileSizeAuthor
#2 changes.patch3.75 KBritarshi_chakraborty

Issue fork flag-3568234

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

ritarshi_chakraborty’s picture

Status: Active » Needs review
StatusFileSize
new3.75 KB

eduardo morales alberti’s picture

Created MR using PHP Attributes

ivnish’s picture

Status: Needs review » Needs work

Tests failed and perhaps Drupal 10 support broken (needs check tests first)

ivnish’s picture

Also I can't reproduce this using the latest dev-version