only in patch2: unchanged: --- a/core/lib/Drupal/Core/Form/FormCache.php +++ b/core/lib/Drupal/Core/Form/FormCache.php @@ -4,6 +4,7 @@ use Drupal\Component\Utility\Crypt; use Drupal\Core\Access\CsrfTokenGenerator; +use Drupal\Core\Entity\ContentEntityFormInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface; use Drupal\Core\PageCache\RequestPolicyInterface; @@ -192,9 +193,20 @@ public function setCache($form_build_id, $form, FormStateInterface $form_state) $this->keyValueExpirableFactory->get('form')->setWithExpire($form_build_id, $form, $expire); } + // If the form state contains a content entity form object then the entity + // should be cached together with the computed field values otherwise when + // unserialized the entity might differ from the initial entity used - e.g. + // when referenced entities have changed. + if (($form_object = $form_state->getFormObject()) && ($form_object instanceof ContentEntityFormInterface)) { + $entity = $form_object->getEntity(); + $entity->serializeComputedFieldValues = TRUE; + } if ($data = $form_state->getCacheableArray()) { $this->keyValueExpirableFactory->get('form_state')->setWithExpire($form_build_id, $data, $expire); } + if (isset($entity)) { + $entity->serializeComputedFieldValues = FALSE; + } } /**