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,7 @@ // 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. - if (!$this->entity->isNew() && $values['target_id'] !== NULL && ($entity_id !== $values['target_id'])) { + 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.'); } } only in patch2: unchanged: --- a/core/lib/Drupal/Core/Form/FormState.php +++ b/core/lib/Drupal/Core/Form/FormState.php @@ -1163,7 +1163,8 @@ public function setFormObject(FormInterface $form_object) { * {@inheritdoc} */ public function getFormObject() { - return $this->getBuildInfo()['callback_object']; + $build_info = $this->getBuildInfo(); + return isset($build_info['callback_object']) ? $build_info['callback_object'] : NULL; } /** only in patch2: unchanged: --- a/core/lib/Drupal/Core/Form/FormStateInterface.php +++ b/core/lib/Drupal/Core/Form/FormStateInterface.php @@ -590,8 +590,8 @@ public function prepareCallback($callback); /** * Returns the form object that is responsible for building this form. * - * @return \Drupal\Core\Form\FormInterface - * The form object. + * @return \Drupal\Core\Form\FormInterface|NULL + * The form object or NULL if not set. */ public function getFormObject();