diff -u b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php --- b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php @@ -189,7 +189,10 @@ $entity_id = $this->get('entity')->getTargetIdentifier(); // If the entity has been saved and we're trying to set both the // target_id and the entity values with a non-null target ID, then the - // value for target_id should match the ID of the entity value. + // value for target_id should match the ID of the entity value. The + // entity ID as returned by $entity->id() might be a string, but the + // provided target_id might be an integer - therefore we have to do a + // non-strict comparison. if (!$this->entity->isNew() && $values['target_id'] !== NULL && ($entity_id != $values['target_id'])) { throw new \InvalidArgumentException('The target id and entity passed to the entity reference item do not match.'); }