Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
NodeFormController::validate() starts with
$node = $this->buildEntity($form, $form_state);
and then calls parent::validate(), which does its own call to
$entity = $this->buildEntity($form, $form_state);
The #entity_builders callbacks and field_attach_submit() are thus called twice for validation only.
With EntityFormController::submit() performing its own call to buildEntity(), that's 3 iterations for one node edit submission.
Comment | File | Size | Author |
---|---|---|---|
#1 | 1768526-1.patch | 1.58 KB | swentel |
#7 | 1768526-7.patch | 3.33 KB | Berdir |
#10 | interdiff.txt | 2.9 KB | swentel |
#10 | 1768526-10.patch | 4.06 KB | swentel |
Comments
Comment #1
swentel CreditAttribution: swentel commented#1938352: Things (for a lack of a better description) are happening twice with some entity forms is maybe related.
Just trying out something here.
Comment #3
BerdirThat will actually survive form submissions because we serialize and then unserialize the (entity) from object, so that won't work. We need to rebuild after re-submitting.
Comment #4
yched CreditAttribution: yched commentedBumping the issue, and also bumping the priority.
On a node form submit, we run "extract form values into field values" 3 times on all fields. Same for aggregator feed forms :
NodeForm::validate() & FeedForm::validate() each call buildEntity() for their own logic, and then call parent::validate(), which calls buildEntity() itself as if we hadn't just built it.
Feels a little absurd that the entity being built is lost between MyEntityForm::validate() and the parent implementation ?
Also feels a little absurd that we'll need to rebuild the entity once more in the submit ?
Comment #5
yched CreditAttribution: yched commentedThis was mentioned in #2406103: Remove hook_node_validate() and hook_node_submit() because they bypass the entity API, which removes most of, but not all, the content of NodeForm::validate().
In #19 / #20 over there:
Any takers ? :-)
Comment #6
yched CreditAttribution: yched commentedComment #7
BerdirSomething like this?
Comment #8
yched CreditAttribution: yched commentedSweet !
Comment #9
alexpottNow the inheritdoc is wrong because this implementation does not return the entity. Should we change EntityFormInterface::validate to return the entity? And then fix all implementations?
Comment #10
swentel CreditAttribution: swentel commentedLike this ? I guess it makes sense to return because when for some reason I'd swap out one of these forms and extend on the defaults, I wouldn't have the validated entity in my custom class.
Comment #11
yched CreditAttribution: yched commentedThanks @swentel :-)
Comment #12
alexpottThis issue addresses a major bug and is allowed per https://www.drupal.org/core/beta-changes. Committed 0b5f5ce and pushed to 8.0.x. Thanks!
Comment #14
fago#2443797: Follow-up to fix EntityFormInterface::validate() return documentation
That was wrong - created #2443797: Follow-up to fix EntityFormInterface::validate() return documentation.