You are here

function webform_component_edit_form_submit in Webform 7.4

Same name and namespace in other branches
  1. 5.2 webform_components.inc \webform_component_edit_form_submit()
  2. 6.3 includes/webform.components.inc \webform_component_edit_form_submit()
  3. 6.2 webform_components.inc \webform_component_edit_form_submit()
  4. 7.3 includes/webform.components.inc \webform_component_edit_form_submit()

Submit handler for webform_component_edit_form().

File

includes/webform.components.inc, line 654
Webform module component handling.

Code

function webform_component_edit_form_submit($form, &$form_state) {

  // Ensure a webform record exists.
  $node = $form['#node'];
  webform_ensure_record($node);

  // Remove extra values that match the default.
  if (isset($form_state['values']['extra'])) {
    $default = array(
      'type' => $form_state['values']['type'],
      'extra' => array(),
    );
    webform_component_defaults($default);
    foreach ($form_state['values']['extra'] as $key => $value) {
      if (isset($default['extra'][$key]) && $default['extra'][$key] === $value) {
        unset($form_state['values']['extra'][$key]);
      }
    }
  }

  // Remove empty attribute values.
  if (isset($form_state['values']['extra']['attributes'])) {
    foreach ($form_state['values']['extra']['attributes'] as $key => $value) {
      if ($value === '') {
        unset($form_state['values']['extra']['attributes'][$key]);
      }
    }
  }
  if ($form_state['values']['clone']) {
    webform_component_clone($node, $form_state['values']);
    drupal_set_message(t('Component %name cloned.', array(
      '%name' => $form_state['values']['name'],
    )));
  }
  elseif (!empty($form_state['values']['cid'])) {
    webform_component_update($form_state['values']);
    drupal_set_message(t('Component %name updated.', array(
      '%name' => $form_state['values']['name'],
    )));
  }
  else {
    $cid = webform_component_insert($form_state['values']);
    drupal_set_message(t('New component %name added.', array(
      '%name' => $form_state['values']['name'],
    )));
  }

  // Since Webform components have been updated but the node itself has not
  // been saved, it is necessary to explicitly clear the cache to make sure
  // the updated webform is visible to anonymous users. This resets the page
  // and block caches (only).
  cache_clear_all();

  // Refresh the entity cache, should it be cached in persistent storage.
  entity_get_controller('node')
    ->resetCache(array(
    $node->nid,
  ));
  $form_state['redirect'] = array(
    'node/' . $node->nid . '/webform/components',
    isset($cid) ? array(
      'query' => array(
        'cid' => $cid,
      ),
    ) : array(),
  );
}