You are here

function custom_pub_edit_submit in Custom Publishing Options 7

Same name and namespace in other branches
  1. 6 custom_pub.module \custom_pub_edit_submit()

Form submit function for the edit form.

1 string reference to 'custom_pub_edit_submit'
custom_pub_edit in ./custom_pub.admin.inc
Form callback function for the edit form.

File

./custom_pub.admin.inc, line 243
Admin functions.

Code

function custom_pub_edit_submit($form, &$form_state) {
  $node_types = _node_types_build();
  $type = $form_state['values']['type'];
  $types = variable_get('custom_pub_types', array());
  if ($form_state['values']['op'] == t('Delete')) {
    $op = t('Deleted');
    unset($types[$type['type']]);
    try {
      db_drop_field('node', $type['type']);
      $success = TRUE;
    } catch (Exception $e) {
      $success = FALSE;
      watchdog_exception('custom_pub', $e, NULL, WATCHDOG_ERROR);
    }
  }
  else {
    $op = t('Edited');
    unset($types[$type['type']]['node_types']);
    foreach ($form_state['values']['node_types'] as $node_type => $value) {
      if (!empty($value)) {
        $types[$type['type']]['node_types'][$node_type] = $node_types->types[$node_type]->name;
      }
    }
    $type['name'] = trim($form_state['values']['state']);
    $types[$type['type']]['name'] = $type['name'];
    $success = TRUE;
  }
  if ($success) {
    cache_clear_all('*', 'cache', TRUE);
    variable_set('custom_pub_types', $types);
    drupal_set_message(t('!op the publishing option %name.', array(
      '!op' => $op,
      '%name' => trim($form_state['values']['state']),
    )));
  }
  else {
    drupal_set_message(t('There was an error trying to !op the publishing option. Please Try Again', array(
      '!op' => $form_state['values']['op'],
    )), 'error');
  }
}