You are here

function features_taxonomy_machine_name_validate in Features 6

1 string reference to 'features_taxonomy_machine_name_validate'
_features_form_taxonomy_form_vocabulary_alter in includes/features.taxonomy.inc

File

includes/features.taxonomy.inc, line 147

Code

function features_taxonomy_machine_name_validate($element, &$form_state) {

  // Validate format - lowecase + underscore only...
  if (!empty($element['#value']) && !preg_match('!^[a-z0-9_]+$!', $element['#value'])) {
    form_error($element, t('The machine name can only consist of lowercase letters, underscores, and numbers.'));
  }

  // If provided check machine name for conflicts and prepend with 'features'.
  if (!empty($element['#value'])) {
    $name = 'features_' . $element['#value'];
    $vid = db_result(db_query("SELECT vid FROM {vocabulary} WHERE module = '%s'", $name));
    if ($vid) {
      form_error($element, t('This machine name is already taken. Please enter a unique machine name or this taxonomy.'));
    }
    else {
      $form_state['values']['module'] = $name;
    }
  }
  else {
    $form_state['values']['module'] = 'taxonomy';
  }
}