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.
I'm doing a form_alter for the webform_component_edit_form. The form itself has access to the current webform $node because it is loaded by the menu router and sent as an argument in includes/webform.components.inc.
function webform_component_edit_form($form, $form_state, $node, $component, $clone = FALSE) {
drupal_set_title(t('Edit component: @name', array('@name' => $component['name'])), PASS_THROUGH);
$form['#attached']['library'][] = array('webform', 'admin');
$form['#tree'] = TRUE;
...
}
But then when there is a form alter, you have to load the node again, and in the submit hook for that same form we are loading the node again as well.
function webform_component_edit_form_validate($form, &$form_state) {
$node = node_load($form_state['values']['nid']);
...
}
Why not just add the $node object to the form? It seems like that would give other modules access and save on a taxing node_load.
Comment | File | Size | Author |
---|---|---|---|
#4 | webform-node-object-in-form-2070571-4.patch | 1.96 KB | quicksketch |
#2 | webform-node-object-in-form-2070571-2.patch | 953 bytes | asherry |
Comments
Comment #1
asherry CreditAttribution: asherry commentedComment #2
asherry CreditAttribution: asherry commentedComment #3
quicksketchLooks good to me. I'll give this a review next time I'm going through the needs review queue.
Comment #4
quicksketchLooks like this change was causing an error on the component form for me. It required switching a foreach() loop to only loop through element children instead of all keys (which we shouldn't have been doing anyway).
Comment #5
quicksketchCommitted to 7.x-4.x.
Comment #6.0
(not verified) CreditAttribution: commentedUpdated issue summary.