Document #entity_builders EntityForm callbacks

Created on 28 February 2017, almost 8 years ago
Updated 27 May 2024, 7 months ago

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

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

11.0 🔥

Component
Documentation 

Last updated 6 days ago

No maintainer
Created by

🇫🇷France andypost

Live updates comments and jobs are added and updated live.
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.

  • 🇬🇧United Kingdom joachim

    > 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.

  • 🇩🇪Germany Grevil

    Bumping once again, as I am not sure when and why to use this, for example when hooking into a form.

  • 🇩🇪Germany geek-merlin Freiburg, Germany

    @Grevil: It's the standardized way of extracting form values / building the entity, and used not only in submit.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    (I am removing a tag, since tags should not duplicate what already selected for the Component field. I apologize for bumping this issue.)

  • 🇪🇨Ecuador jwilson3

    Bump. 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.

Production build 0.71.5 2024