diff --git a/core/lib/Drupal/Core/Entity/ContentEntityForm.php b/core/lib/Drupal/Core/Entity/ContentEntityForm.php index c0882a2..3740600 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityForm.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityForm.php @@ -50,10 +50,10 @@ public static function create(ContainerInterface $container) { */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); - - // Content entity forms only need to rebuild the entity in the validation - // and the submit handler because Field API uses its own #after_build - // callback for its widgets. + // Content entity forms do not use the parent's #after_build callback + // because they only need to rebuild the entity in the validation and the + // submit handler because Field API uses its own #after_build callback for + // its widgets. unset($form['#after_build']); $this->getFormDisplay($form_state)->buildForm($this->entity, $form, $form_state); diff --git a/core/lib/Drupal/Core/Entity/EntityForm.php b/core/lib/Drupal/Core/Entity/EntityForm.php index d5b2c7a..fb015c7 100644 --- a/core/lib/Drupal/Core/Entity/EntityForm.php +++ b/core/lib/Drupal/Core/Entity/EntityForm.php @@ -158,12 +158,13 @@ public function processForm($element, FormStateInterface $form_state, $form) { /** * Form element #after_build callback: Updates the entity with submitted data. * - * This is the entity object builder function that allows rebuilt forms (e.g. - * submitted via AJAX) to keep relying on entity values instead of form state. + * Updates the internal $this->entity object with submitted values when the + * form is being rebuilt (e.g. submitted via AJAX), so that subsequent + * processing (e.g. AJAX callbacks) can rely on it. */ public function afterBuild(array $element, FormStateInterface $form_state) { - // If the form is processing user input, rebuild the entity with the current - // form values. + // Rebuild the entity if #after_build is being called as part of a form + // rebuild, i.e. if we are processing input. if ($form_state->isProcessingInput()) { $this->entity = $this->buildEntity($element, $form_state); }