You are here

function token_custom_edit_form_submit in Custom Tokens 7.2

Same name and namespace in other branches
  1. 5 token_custom.module \token_custom_edit_form_submit()
  2. 6 token_custom.module \token_custom_edit_form_submit()
  3. 7 token_custom.admin.inc \token_custom_edit_form_submit()

Submit handler for the custom token admin form.

Tries to save the added/edited token.

Parameters

array $form: The form array.

array $form_state: The form state array.

File

./token_custom.admin.inc, line 341
Page callbacks and admin forms of the token_custom module.

Code

function token_custom_edit_form_submit($form, &$form_state) {
  if ($form_state['token_custom']['op'] == 'edit' && $form_state['triggering_element']['#id'] == 'edit-delete') {
    $form_state['redirect'] = 'admin/structure/token-custom/' . $form_state['values']['machine_name'] . '/delete';
    return;
  }
  $form_state['values']['is_new'] = $form_state['token_custom']['op'] == 'add';
  $token = array(
    'name' => $form_state['values']['name'],
    'machine_name' => $form_state['values']['machine_name'],
    'description' => $form_state['values']['description'],
    'type' => $form_state['values']['type'],
    'content' => $form_state['values']['content']['value'],
    'format' => $form_state['values']['content']['format'],
    'is_new' => $form_state['values']['is_new'],
  );
  if (!token_custom_save($token)) {
    drupal_set_message(t('There was a problem saving token <em>@machine_name</em>. Please contact the site administrator.', array(
      '@machine_name' => $form_state['values']['machine_name'],
    )), 'error');
  }
  else {
    drupal_set_message(t('Token <em>@machine_name</em> saved.', array(
      '@machine_name' => $form_state['values']['machine_name'],
    )));
  }
  $form_state['redirect'] = 'admin/structure/token-custom';
}