Problem/Motivation

The $context_definitions param for the Block attribute is expecting \Drupal\Core\Annotation\ContextDefinition[]. This was added in #3252386: Use PHP attributes instead of doctrine annotations, yet in #3421019: Convert SectionStorage plugin discovery to attributes we're expecting \Drupal\Component\Plugin\Context\ContextDefinitionInterface[], which the previously mentioned class does not inherit from. It's possibly been mixed up with \Drupal\Core\Plugin\Context\ContextDefinition. Note the similar name but different namespace.

Steps to reproduce

The following attribute causes phpstan grief:

#[Block(
  id: "my_block",
  admin_label: new TranslatableMarkup("My block."),
  context_definitions: [
    'node' => new EntityContextDefinition(
      data_type: 'entity:node',
      label: 'Node Context',
      required: FALSE,
    ),
  ],
)]

Proposed resolution

  • Confirm which class/interface we're meant to use
  • Fix it

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3425568

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

mstrelan created an issue. See original summary.

mstrelan’s picture

mstrelan’s picture

Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Simple enough change and makes sense.

longwave’s picture

Version: 11.x-dev » 10.2.x-dev
Status: Reviewed & tested by the community » Fixed

Backported to 10.2.x as a docs bug fix.

Committed and pushed eb10b68667 to 11.x and 39df12b2ed to 10.3.x and cd2c8e49c8 to 10.2.x. Thanks!

  • longwave committed cd2c8e49 on 10.2.x
    Issue #3425568 by mstrelan: Block attribute class expecting wrong...

  • longwave committed 39df12b2 on 10.3.x
    Issue #3425568 by mstrelan: Block attribute class expecting wrong...

  • longwave committed eb10b686 on 11.x
    Issue #3425568 by mstrelan: Block attribute class expecting wrong...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.