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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

asherry’s picture

Version: 7.x-4.0-alpha10 » 7.x-4.x-dev
asherry’s picture

Status: Active » Needs review
FileSize
953 bytes
quicksketch’s picture

Looks good to me. I'll give this a review next time I'm going through the needs review queue.

quicksketch’s picture

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

quicksketch’s picture

Status: Needs review » Fixed

Committed to 7.x-4.x.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Updated issue summary.