In ValidDynamicReferenceConstraintValidator at 153 the foreach loop overwrites the $entity variables, resulting in wrong object being passed to SelectionPluginManager::getSelectionHandler() at 187.

Comments

adr_p created an issue. See original summary.

adr_p’s picture

larowlan’s picture

Status: Active » Needs work
+++ src/Plugin/Validation/Constraint/ValidDynamicReferenceConstraint2.php	2022-05-02 07:18:24.284585529 +0200
@@ -109,11 +109,11 @@
     foreach ($new_entities as $delta => $new_entity) {
       /** @var \Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface $handler */
-      $handler = $this->selectionManager->getSelectionHandler($value->getFieldDefinition(), $entity, $target_types[$delta]);

the loop is using $new_entity, where is the collision happening, might be missing some context with the patch