Change record status: 
Project: 
Introduced in branch: 
8.0.x
Introduced in version: 
8.0.0-RC4
Description: 

In order to properly validate the values of an entity reference field in all situations (e.g. form submissions, REST operations, etc.), the validation logic has been moved to the Entity Reference Selection plugins and is now invoked by the ValidReference constraint.

Additionally, the ValidReference constraint has been changed to only deal with FieldItemList objects instead of FieldItem objects. As a consequence, it was removed from the entity reference field type annotation to its getConstraints() method, which means that any field type that extends entity reference should not specify it in their respective annotation as well.

This change also affects field values that are created "on the fly", either through an autocomplete field widget or by manually populating the 'entity' property of an entity reference field (i.e. $entity->reference_field->entity = $new_referenced_entity).

For this purpose, a new SelectionWithAutocreateInterface interface was introduced, and it is implemented in core only by the 'Default' selection plugin. The 'Views' selection plugin can not handle auto-created entities so it does not implement the new interface.

Contributed and custom modules that are implementing their own selection plugins will have to implement this interface if they want to support references for newly-created entities.

In order to be sure that newly-created entities are valid references, the Core\Entity\Element\EntityAutocomplete::createNewEntity() method was also moved to the new SelectionWithAutocreateInterface interface, because selection plugins already contain the logic about what makes an entity a valid reference.

Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done