You are here

function custom_pub_add_submit in Custom Publishing Options 7

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

Submit handler

_state

Parameters

$form:

File

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

Code

function custom_pub_add_submit($form, &$form_state) {
  $types = variable_get('custom_pub_types', array());
  $node_types = _node_types_build();
  $type = array();
  $type[trim($form_state['values']['state_machine'])]['type'] = trim($form_state['values']['state_machine']);
  $type[trim($form_state['values']['state_machine'])]['name'] = trim($form_state['values']['state']);
  foreach ($form_state['values']['node_types'] as $node_type => $value) {
    if (!empty($value)) {
      $type[trim($form_state['values']['state_machine'])]['node_types'][$node_type] = $node_types->types[$node_type]->name;
    }
  }
  $spec = array(
    'description' => 'Custom publishing option ' . t(trim($form_state['values']['state'])),
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  );
  try {
    db_add_field('node', trim($form_state['values']['state_machine']), $spec);
    $success = TRUE;
  } catch (Exception $e) {
    $success = FALSE;
    watchdog_exception('custom_pub', $e, NULL, WATCHDOG_ERROR);
  }
  if ($success) {
    cache_clear_all('*', 'cache', TRUE);
    variable_set('custom_pub_types', array_merge($types, $type));
    drupal_set_message(t('Publishing option %option created.', array(
      '%option' => $form_state['values']['state'],
    )));
    $form_state['redirect'] = 'admin/structure/custom_pub';
  }
  else {
    drupal_set_message(t('There was an error creating your Publishing option.'), 'error');
  }
}