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.
Currently there is no general way to re-use entity forms.
Attached patch implements another entity helper, entity_form() which allows that. The patch works for me with all core entity types, as well as entity types using the entity API admin ui. We should add some tests for the form though.
Comment | File | Size | Author |
---|---|---|---|
#9 | entity_form_defaults.patch | 567 bytes | fago |
#9 | profile2_form_defaults.patch | 534 bytes | fago |
#3 | profile2_entity_form.patch | 900 bytes | fago |
#2 | entity_form_harmonize_drush_make.patch | 10.41 KB | fago |
#1 | entity_form_harmonize.patch | 10.43 KB | fago |
Comments
Comment #1
fagoSomehow the vocabulary callback got lost, new patch attached.
Comment #2
fagoand one for drush make users
Comment #3
fagothis is a patch for profile2 to support entity_form().
Comment #4
scroogie CreditAttribution: scroogie commentedVery interesting, subscribing.
Comment #5
fagoCommitted.
Comment #7
amitaibu$form_state is undefined. Should it be an empty array?
I'm looking at it for Message - I'd like to provide a UI for users to CRUD message (i.e. message instance not message type).
Comment #8
sunOink.
First arguments should obviously be $form, $form_state...
:(
$form_state is never empty in D7. Should at least be form_state_defaults(), prepared and provided by the function invoking the hook.
Comment #9
fagoentity_form() is supposed to build and process the form for you - there is no possibility to embed forms in others or similar. That way there is no point or possibility to customize $form and $form_state.
This would be certainly nice, but I fear that would basically require a subform element for d7...
Right. Fix attached, please review.
Comment #11
fmizzell CreditAttribution: fmizzell commentedsub
Comment #12
tim.plunkettThis prevents entity_form from being used in ctools modals. That needs a custom form_state.
A possible workaround for that is entity_metadata_form_id_* to complement entity_metadata_form_*.
Unsure about the &$form part, but this would really help with the ctools modal stuff.
Comment #13
fagoI've committed the fix from #9.
ad #12 : I see. Well we could add an optional parameter $form_state to entity_form() what allows prepopulating it that way. Anyway, let's please use a separate issue for improving this.
Comment #14
tim.plunkettOpened #1437902: Allow custom $form_state to be used with entity_form()