You are here

function taxonomy_machine_name_clean_name in Taxonomy Machine Name 7

Same name and namespace in other branches
  1. 8 taxonomy_machine_name.module \taxonomy_machine_name_clean_name()

Clean name to generate machine name.

Parameters

string $name: Name to clean.

bool $force: Force new machine name.

Return value

string Cleaned name.

1 call to taxonomy_machine_name_clean_name()
taxonomy_machine_name_taxonomy_term_presave in ./taxonomy_machine_name.module
Implements hook_taxonomy_term_presave().
1 string reference to 'taxonomy_machine_name_clean_name'
MigrateTaxonomyTermReferenceMachineNameFieldHandler::prepare in ./taxonomy_machine_name.migrate.inc
Prepare destination field.

File

./taxonomy_machine_name.module, line 159

Code

function taxonomy_machine_name_clean_name($name, $force = FALSE) {
  if (!preg_match('/^[a-z0-9\\_]+$/i', $name) || $force) {
    if (module_exists('pathauto')) {

      // Better sluggify code including transliteration.
      module_load_include('inc', 'pathauto');
      $machine_name = pathauto_cleanstring(str_replace('_', variable_get('pathauto_separator', '-'), $name));
      $machine_name = str_replace(variable_get('pathauto_separator', '-'), '_', $machine_name);
    }
    elseif (module_exists('token')) {

      // Avoid duplicate code.
      module_load_include('module', 'token');
      $machine_name = token_clean_token_name($name);
      $machine_name = str_replace('-', '_', drupal_strtolower($machine_name));
    }
    else {

      // Final fallback.
      $machine_name = drupal_strtolower(str_replace('_', '-', $name));
    }

    // Remove remaining accents.
    $machine_name = preg_replace('/[^a-z0-9\\_]/iu', '_', $machine_name);
    $machine_name = trim($machine_name, '_');
  }
  else {
    $machine_name = trim(drupal_strtolower($name));
  }
  drupal_alter('taxonomy_machine_name_clean_name', $machine_name, $name, $force);
  return $machine_name;
}