You are here

function taxonomy_csv_vocabulary_machine_name_create in Taxonomy CSV import/export 7.5

Same name and namespace in other branches
  1. 7.4 taxonomy_csv.vocabulary.api.inc \taxonomy_csv_vocabulary_machine_name_create()

Creates a machine name from a string.

The name is created by replacing non alphanumeric character by an underscore. Machine name is defined as first 16 cleaned characters of name and a random five characters serial. Fields module prepends 'taxonomy_' to name and check if total lenght is 21 characters max.

Parameters

$name: The string to process.

Return value

The processed string.

2 calls to taxonomy_csv_vocabulary_machine_name_create()
taxonomy_csv_vocabulary_create in ./taxonomy_csv.vocabulary.api.inc
Creates vocabulary by its name and returns vocabulary object.
_taxonomy_csv_vocabulary_name_create in ./taxonomy_csv.vocabulary.api.inc
Helper to create an unused vocabulary name from a string.

File

./taxonomy_csv.vocabulary.api.inc, line 75
Prepare and manage vocabularies.

Code

function taxonomy_csv_vocabulary_machine_name_create($name) {

  // Get last vid.
  $vid = 1 + db_query('SELECT max(vid) FROM {taxonomy_vocabulary}')
    ->fetchField();
  $machine_name = drupal_substr(preg_replace('/_+/i', '_', preg_replace('/[^a-z0-9\\_]/i', '_', drupal_strtolower(trim(strval($name))))), 0, 16) . $vid . '_' . strval(rand(10000, 99999));
  return drupal_substr($machine_name, 0, 21);
}