diff --git a/core/lib/Drupal/Core/Entity/EntityForm.php b/core/lib/Drupal/Core/Entity/EntityForm.php index 43b5da36ab..017239e46d 100644 --- a/core/lib/Drupal/Core/Entity/EntityForm.php +++ b/core/lib/Drupal/Core/Entity/EntityForm.php @@ -217,10 +217,12 @@ protected function synchronizeEntityBetweenGetAndPostRequests(FormStateInterface break; case 'POST': $user_input = $form_state->getUserInput(); - $this->entitySyncHashKey = $user_input['entity_sync_hash_key']; - $entity = $key_value_store->get($this->entitySyncHashKey); - $entity = unserialize($entity); - $this->entity = $entity; + if (isset($user_input['entity_sync_hash_key'])) { + $this->entitySyncHashKey = $user_input['entity_sync_hash_key']; + $entity = $key_value_store->get($this->entitySyncHashKey); + $entity = unserialize($entity); + $this->entity = $entity; + } break; } } @@ -239,10 +241,12 @@ public function form(array $form, FormStateInterface $form_state) { // The entity sync hash key must be sent to the client, in order to be able // to load the entity used to build the form in later form requests. - $form['entity_sync_hash_key'] = [ - '#type' => 'hidden', - '#default_value' => $this->entitySyncHashKey, - ]; + if (isset($this->entitySyncHashKey)) { + $form['entity_sync_hash_key'] = [ + '#type' => 'hidden', + '#default_value' => $this->entitySyncHashKey, + ]; + } return $form; }