$entity = !
empty($value->
getParent()) ?
$value->
getEntity() : NULL;
/** @var \Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface $handler * */
$handler =
$this->selectionManager->
getSelectionHandler($value->
getFieldDefinition(),
$entity);
$target_type_id =
$value->
getFieldDefinition()->
getSetting('target_type'
);
// Add violations on deltas with a new entity that is not valid.
if ($new_entities) { if ($handler instanceof SelectionWithAutocreateInterface
) { $valid_new_entities =
$handler->
validateReferenceableNewEntities($new_entities);
$invalid_new_entities =
array_diff_key($new_entities,
$valid_new_entities);
} else { // If the selection handler does not support referencing newly created
// entities, all of them should be invalidated.
$invalid_new_entities =
$new_entities;
} foreach ($invalid_new_entities as $delta =>
$entity) { $this->context->
buildViolation($constraint->invalidAutocreateMessage
) ->
setParameter('%type',
$target_type_id)