Problem/Motivation
ContextDefinition::isSatisfiedBy does not check if the definition is multi-valued. This can cause an error when checking violations.
Steps to reproduce
The following code produces an error.
$definition = EntityContextDefinition::create('node');
$definition->setMultiple();
$nodes = Node::loadMultiple([1, 1]);
$context = new \Drupal\Core\Plugin\Context\Context($definition, $nodes);
$satisfied = $definition->isSatisfiedBy($context);
Error: Call to a member function getEntityTypeId() on array in Drupal\Core\Entity\Plugin\Validation\Constraint\EntityTypeConstraintValidator->validate() (line 22 of /var/www/html/web/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/EntityTypeConstraintValidator.php).
Proposed resolution
Check $definition->isMultiple() inside of ContextDefinition::isSatisfiedBy and tweak how $validator->validate() runs.
Remaining tasks
Write a patch.
User interface changes
n/a
API changes
n/a
Data model changes
n/a
Release notes snippet
n/a
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 3314469_context_multiple_definition-4.test.patch | 1.14 KB | plach |
| #3 | 3314469_context_multiple_definition.patch | 2.46 KB | alecsmrekar |
Issue fork drupal-3314469
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
Comment #3
alecsmrekar commentedAdded patch
Comment #4
alecsmrekar commentedComment #5
plachLooks good to me, posting a test-only version of the patch to verify that the test does provide coverage for the bug.
Comment #6
plachComment #7
plachComment #9
plachOk, test patch failing as expected!
Patch to commit at #3.
Comment #11
catchCommitted/pushed to 10.1.x, cherry-picked back through to 9.4.x, thanks!