Block attribute class expecting wrong ContextDefinition

Created on 4 March 2024, 10 months ago
Updated 20 March 2024, 10 months ago

Problem/Motivation

The $context_definitions param for the Block attribute is expecting \Drupal\Core\Annotation\ContextDefinition[]. This was added in πŸ“Œ Use PHP attributes instead of doctrine annotations Fixed , yet in πŸ“Œ Convert SectionStorage plugin discovery to attributes Needs work 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

πŸ› Bug report
Status

Fixed

Version

10.2 ✨

Component
BlockΒ  β†’

Last updated 1 day ago

Created by

πŸ‡¦πŸ‡ΊAustralia mstrelan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024