1 taxonomy.admin.inc taxonomy_form_vocabulary_submit($form, &$form_state)

Form submission handler for taxonomy_form_vocabulary().

See also

taxonomy_form_vocabulary()

taxonomy_form_vocabulary_validate()

File

core/modules/taxonomy/taxonomy.admin.inc, line 304
Administrative page callbacks for the taxonomy module.

Code

function taxonomy_form_vocabulary_submit($form, &$form_state) {
  if ($form_state['triggering_element']['#value'] == t('Delete')) {
    // Rebuild the form to confirm vocabulary deletion.
    $form_state['rebuild'] = TRUE;
    $form_state['confirm_delete'] = TRUE;
    return;
  }

  $vocabulary = $form_state['vocabulary'];
  form_state_values_clean($form_state);
  foreach ($form_state['values'] as $key => $value) {
    $vocabulary->$key = $value;
  }

  // Prevent leading and trailing spaces in vocabulary names.
  $vocabulary->name = trim($vocabulary->name);

  switch (taxonomy_vocabulary_save($vocabulary)) {
    case SAVED_NEW:
      backdrop_set_message(t('Created new vocabulary %name.', array('%name' => $vocabulary->name)));
      watchdog('taxonomy', 'Created new vocabulary %name.', array('%name' => $vocabulary->name), WATCHDOG_NOTICE, l(t('configure'), 'admin/structure/taxonomy/' . $vocabulary->machine_name . '/configure'));
      $form_state['redirect'] = 'admin/structure/taxonomy/' . $vocabulary->machine_name;
      // Save new permissions
      foreach ($form_state['values']['roles'] as $role_name => $role) {
        $valid_perms = array();
        // Create the permissions string in the format 'edit terms in $vocab'.
        foreach ($form_state['values'][$role->name] as $string => $perm) {
          if ($perm) {
            $parts = explode(' terms in ', $string);
            $valid_perms[] = $parts[0] . ' terms in ' . $vocabulary->machine_name;
          }
        }
        user_role_grant_permissions($role->name, $valid_perms);
      }
      break;

    case SAVED_UPDATED:
      backdrop_set_message(t('Updated vocabulary %name.', array('%name' => $vocabulary->name)));
      watchdog('taxonomy', 'Updated vocabulary %name.', array('%name' => $vocabulary->name), WATCHDOG_NOTICE, l(t('configure'), 'admin/structure/taxonomy/' . $vocabulary->machine_name . '/configure'));
      $form_state['redirect'] = 'admin/structure/taxonomy';
      // Update permissions.
      foreach ($form_state['values']['roles'] as $role_name => $role) {
        user_role_change_permissions($role->name, $form_state['values'][$role->name]);
      }
      break;
  }
}