You are here

function devel_generate_vocabs in Devel 7

Same name and namespace in other branches
  1. 5 devel_generate.inc \devel_generate_vocabs()
  2. 6 devel_generate.inc \devel_generate_vocabs()
2 calls to devel_generate_vocabs()
devel_generate_vocab_form_submit in devel_generate/devel_generate.module
FormAPI submission to generate taxonomy vocabularies.
drush_devel_generate_vocabs in devel_generate/devel_generate.drush.inc
Command callback. Generate a number of vocabularies.

File

devel_generate/devel_generate.inc, line 184

Code

function devel_generate_vocabs($records, $maxlength = 12, $types = array(
  'page',
  'article',
)) {
  $vocs = array();

  // Insert new data:
  for ($i = 1; $i <= $records; $i++) {
    $voc = new stdClass();
    $voc->name = devel_generate_word(mt_rand(2, $maxlength));
    $voc->machine_name = drupal_strtolower($voc->name);
    $voc->description = "description of " . $voc->name;

    // TODO: not working
    $voc->nodes = array_flip(array(
      $types[array_rand($types)],
    ));
    foreach ($voc->nodes as $key => $value) {
      $voc->nodes[$key] = $key;
    }
    $voc->multiple = 1;
    $voc->required = 0;
    $voc->relations = 1;
    $voc->hierarchy = 1;
    $voc->weight = mt_rand(0, 10);
    $voc->language = LANGUAGE_NONE;
    taxonomy_vocabulary_save($voc);
    $vocs[] = $voc->name;
    unset($voc);
  }
  return $vocs;
}