Document that #entity_builders and overrides of EntityForm::copyFormValuesToEntity() must be idempotent

Created on 13 September 2016, over 8 years ago
Updated 22 August 2024, 4 months ago

Problem/Motivation

Currently, any implementations of \Drupal\Core\Entity\EntityForm::copyFormValuesToEntity(), or any #entity_builders callback will be run twice on form submit.

This is usually not a problem, as they copy things from $form_state->getValues() to the $entity.

It becomes problematic when your code checks the old values in comparison to the new values. In this case, on the second run, different code paths will be followed.


This is purposeful, because content entities must be updated with the form values in order to be validated.

Proposed resolution

Document it.

Remaining tasks

Document it.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

πŸ“Œ Task
Status

Closed: outdated

Version

11.0 πŸ”₯

Component
EntityΒ  β†’

Last updated about 17 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States tim.plunkett Philadelphia

Live updates comments and jobs are added and updated live.
  • Documentation

    Primarily changes documentation, not code. For Drupal core issues, select the Documentation component instead of using this tag. In general, component selection is preferred over tag selection.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024