Why aren't we sending the entity to the selection handler when validating? Couldn't we just get the entity from the item and add it to the plugin?

See Drupal\Core\Entity\Plugin\Validation\Constraint\ValidReferenceConstraintValidator line 95.

$handler = $this->selectionManager->getSelectionHandler($value->getFieldDefinition(), $item->getEntity());
Members fund testing for the Drupal project. Drupal Association Learn more


_Archy_ created an issue. See original summary.

_Archy_’s picture

_Archy_’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: entity_reference-send_entity_to_selection-2879918-2.patch, failed testing.

_Archy_’s picture

Status: Needs work » Needs review
1.03 KB

Send the entity only if it exists.

amateescu’s picture

Version: 8.3.x-dev » 8.4.x-dev
Status: Needs review » Reviewed & tested by the community

I don't see any reason not to do this :)

amateescu’s picture

For core committers: can you please add @grathbone to the commit message? He worked on the same issue here: #2875747: ValidReferenceConstraintValidator missing field entity

Dinesh18’s picture

I have reviewed the patch manually and we are sending the $entity to getSelectionHandler.
+1 to RTBC

alexpott credited Sam152.

alexpott’s picture

Crediting @grathbone and @sam152 for work on #2875747: ValidReferenceConstraintValidator missing field entity

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 032ad72 and pushed to 8.4.x. Thanks!

I checked public function getSelectionHandler(FieldDefinitionInterface $field_definition, EntityInterface $entity = NULL) { already has an optional entity so providing it is fine.

  • alexpott committed 032ad72 on 8.4.x
    Issue #2879918 by _Archy_, amateescu, Sam152, grathbone: Send entity to...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.