You are here

function taxonomy_unique_term_name_validate in Taxonomy unique 7

Same name and namespace in other branches
  1. 8 taxonomy_unique.module \taxonomy_unique_term_name_validate()

Implements _form_validate() for taxonomy_form_term().

1 string reference to 'taxonomy_unique_term_name_validate'
taxonomy_unique_form_taxonomy_form_term_alter in ./taxonomy_unique.module
Implements hook_form_FORM_ID_alter() for taxonomy_form_term().

File

./taxonomy_unique.module, line 63
Module file for the Taxonomy unique module.

Code

function taxonomy_unique_term_name_validate($form, &$form_state) {

  // If we don't want to save, don't validate the term name.
  if ($form_state['values']['op'] != t('Save')) {
    return;
  }

  // Get the needed variables from $form_state.
  $name = $form_state['values']['name'];
  $vocabulary_machine_name = $form_state['values']['vocabulary_machine_name'];
  $tid = !empty($form_state['values']['tid']) ? $form_state['values']['tid'] : NULL;

  // If the name isn't empty and unique check failed, mark field as invalid.
  if ($name != '' && !taxonomy_unique_is_term_unique($name, $vocabulary_machine_name, $tid)) {
    $error_message = variable_get('taxonomy_unique_' . $vocabulary_machine_name . '_message', TAXONOMY_UNIQUE_DEFAULT_MESSAGE);
    form_set_error('name', filter_xss(format_string($error_message, array(
      '%term' => $name,
      '%vocabulary' => $vocabulary_machine_name,
    ))));
  }
}