EntityContextDefinition defaults to non-existent data type 'entity:any'

Created on 21 October 2021, over 2 years ago
Updated 30 January 2023, over 1 year ago

Problem/Motivation

Some tests for a contrib module I maintain began failing on 9.3.x after the commit for this issue: #3194768: The plugin system should only consider NULL context values to be empty to facilitate the use of otherwise FALSE values β†’ .

The situation with the contrib module is described in the IS and comments: #3245196: Tests failing on 9.3.x β†’

It does not appear that the recent commit referenced above created this bug. Instead it just exposed the bug. The way it exposes the bug is by leveraging ContextDefinitionInterface::getDataDefinition. When called on an entity:any context, things go badly.

The failure appears to be due to fact that

1. Drupal\Core\Plugin\Context\EntityContextDefinition has a default data type of entity:any
2. Theentity:any data type does not exist.

Steps to reproduce

Calling

$context_definition = new Drupal\Core\Plugin\Context\EntityContextDefinition();

will create a new context with the entity:any data type. So the following code throws an exception:

$context_definition = new Drupal\Core\Plugin\Context\EntityContextDefinition();
$data_definitition = $context_definition->getDataDefinition();

Proposed resolution

Rework constructor for EntityContextDefinition such that it creates a ContextDefinition with data type entity by default instead of entity:any. This is inspired by the workaround below.

A workaround is to rely on the entity context rather than the entity:any context. The following does not throw exceptions and seems to work fine:

$context = new Drupal\Core\Plugin\Context\ContextDefinition('entity');
$defintition = $context->getDataDefinition();

Remaining tasks

TBD

User interface changes

None

API changes

TBD

Data model changes

TBD

Release notes snippet

TBD

πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
PluginΒ  β†’

Last updated about 15 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States danflanagan8 St. Louis, US

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot β†’ tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

Production build 0.69.0 2024