I have a Subscription custom entity and I would like to use the default entity form for administration tasks and a custom multistep form for the subscription process.

I added an address field to my Subscription entity and I would like to use the widget in one of the custom form steps.

I was expecting I could use something like '#type' => 'widget_id' plus some widget configuration, but it does not seem to be so simple as this answer points out.

a widget and a form element are two different things that are used in different cases; consider a widget a more specialized type of form element.

What would be the right approach then? In the field_attach_form change record a comment suggests

$display = EntityFormDisplay::collectRenderDisplay($entity, 'default');
$display->buildForm($entity, $form, $form_state);

How do I get just my address field? Form display modes?

And then, how do I deal with validating and storing the data properly?

1 Answer 1


You can limit the $form array's elements by setting their #access property to FALSE.

The validation and storing should be handled by the form for the corresponding entity by itself.

  • Thanks, @rémy, I was hoping for a more explicit method. Altering a whole form just to get a field seems a bit of a work-around, but you may well be right about this being the most proper method currently available. I will wait a few days before accepting your answer to see if we get some other ideas.
    – Esclapes
    Commented Mar 17, 2016 at 8:21
  • Thanks again. At the end I ended up using $display->buildForm and then restricting access with an admin permission check on some fields.
    – Esclapes
    Commented Mar 24, 2016 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.