Problem/Motivation
There's a entity_builders used a lot by core modules to extend entity forms but this api is undocumented
\Drupal\Core\Entity\EntityForm::buildEntity()
$entity = clone $this->entity;
$this->copyFormValuesToEntity($entity, $form, $form_state);
// Invoke all specified builders for copying form values to entity
// properties.
if (isset($form['#entity_builders'])) {
foreach ($form['#entity_builders'] as $function) {
call_user_func_array($function, array($entity->getEntityTypeId(), $entity, &$form, &$form_state));
}
}
return $entity;
Proposed resolution
Define what that for and document somehow
Comments
Comment #2
andypostActual usage
Comment #4
andypost@Tim any idea where to put this docs?
Comment #7
danielvezaJust bumping this up. Looking into these and not finding much info.
Comment #8
tim.plunkettComment #14
ultrabob commentedHi Daniel, I was looking for some documentation, but this is all I could find.
Comment #15
simeI was also looking for this, and the signature for the callback is not documented for any core implementations that I can see. (No @param doxygen.)
Comment #16
anybodyJust found it in this article: https://www.heididev.com/how-alter-configuration-entity-data-drupal-8-or...
I guess it would make sense to document it on the same page where other form callbacks like
#validateor
#submitare documented?
That's at least where I'd expect it.
Comment #17
anybodyComment #20
rp7 commentedI'm having a hard time figuring out when to use an #entity_builder callback and when to use an #element_validate callback to alter (or clear) a submitted value. Anyone that can provide some insights?
Comment #22
mxr576Most probably also covering #2799637: Document that #entity_builders and overrides of EntityForm::copyFormValuesToEntity() must be idempotent here is a good idea.
Comment #23
joachim commented> I guess it would make sense to document it on the same page where other form callbacks like #validate or #submit are documented?
#entity_builders is specific to the EntityForm class though, not a general FormAPI thing.
EntityForm::entityFormEntityBuild() is the thing that consumes these, so that's the logical place to put some documentation.
Maybe the class docs for EntityForm can mention it too. Probably sensible to put the bulk of it there, as it's more immediately visible if you're reading up about that class.
Comment #24
grevil commentedBumping once again, as I am not sure when and why to use this, for example when hooking into a form.
I just found it being used in "field_permissions", for setting third party field storage settings, see (https://git.drupalcode.org/project/field_permissions/-/blob/8.x-1.x/fiel...). Is it not possible to just use a submit Form handler here instead?
Comment #25
geek-merlin@Grevil: It's the standardized way of extracting form values / building the entity, and used not only in submit.
Comment #26
grevil commented@geek-merlin Thanks for the clear-up! I could have realized, that this is the use case from the description of "EntityForm::entityFormEntityBuild()". But I thought it might do something else.
Comment #28
avpaderno(I am removing a tag, since tags should not duplicate what already selected for the Component field. I apologize for bumping this issue.)
Comment #29
jwilson3Bump. I've inherited the Label Help contrib module some time ago and at least two completely separate bugs have been filed which I suspect may be related to the Entity Builders Callback usage in the module. I'm currently trying to figure out why the original author who is no longer around used #entity_builders in code from 7 years ago to set third-party settings.
https://git.drupalcode.org/project/label_help/-/blob/376c641da6a72eb868d...
It seems like this could be done in a #form_submit, but I'm not entirely certain.
I'm creating a tag to group such issues.
Comment #31
anybodyWe're now experiencing taxonomy term overview page order changes not being saved any more if several modules are enabled that implement submit callbacks instead of entity builders for handling additional third party settings on the taxonomy term overview pages.
For us this happens in the combination of
being enabled.
Only if I remove the submit callbacks of all three, the form is saving again, while other modules that use Entity Builders can stay enabled and everything works fine!
No idea if this happens since we upgraded to Drupal 11.3 or what's the root cause, yet. If anyone has an idea, that would be great.
For me, this is just another good reason to replace submit callbacks by Entity Builders wherever it is used to add third party settings altering an existing form!