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
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:
- 3425568-block-attribute-class
changes, plain diff MR !6906
Comments
Comment #2
mstrelan commentedComment #4
mstrelan commentedComment #5
smustgrave commentedSimple enough change and makes sense.
Comment #6
longwaveBackported 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!