I've built a new field_group display formatter called "form" to display the contained fields in a form, allowing users with permission to update an entity the ability to do so right form the "view" of an entity.
This is similar to editablefields, except that in this case I want to be able to display multiple items with 1 submit button, and would also like to have different view_modes for different roles, thereby allowing different users access to different parts of the entity.
The attached code does its job well! However, there are a couple quirks that I would like to get some guidance on if any one can assist. Specifically:
1) The only way I am able to get the form to actually display within the field_group element is by rendering it and forcing it into the $element's markup:
<?php
$element['#markup'] = drupal_render(drupal_get_form('field_group_form_build_form', $group, $form));
?>
This feels a bit brutal, but it's the only way I've been able to get this to work and for the $form_state to actually exist properly throughout the form validation and submission process.
2) Because this is all done at the pre_render (theme) layer, any form error messages set during validation aren't visible until the next page load. I have overcome this by doing the following on the _validate() level:
<?php
$form['field_group_form_fieldset']['errors'] = array(
'#markup' => theme('status_messages'),
'#weight' => 0,
);
?>
but again, it seems a bit brutal. I would hate to display any other messages that I don't care about within this field_group. Ideally, I'd like the messages to display in the standard $messages variable at the 'page' level.
Outside of these 2 it's working well, and there's not too much code here to achieve this functionality so I'm fairly happy with where it's at. Module is attached.
Comment | File | Size | Author |
---|---|---|---|
field_group_form.zip | 1.66 KB | charlie-s |
Comments
Comment #1
charlie-s CreditAttribution: charlie-s commentedI've very quickly discovered that due to field_group_remove_empty_display_groups() and field_group_pre_render() there is no way to get a field_group to display when all of its fields are empty. That sucks. I've opened a second issue (http://drupal.org/node/1482958) requesting that this check look for a field_group setting "show_empty_fields". That may be a good addition to the core field_group module.
Comment #2
nicodv CreditAttribution: nicodv commentedBefore trying it, can you embed different views into panels, so at the end I could have more than one node being edited in one page?
thanks
nico
Comment #3
charlie-s CreditAttribution: charlie-s commentedI've tried multiple nodes in a View (displayed in content format and not field format) and that works, so I don't see why not.
Comment #4
nils.destoop CreditAttribution: nils.destoop as a volunteer and at Wunder commented