down arrowMenu

UNI Webtools: Resources for Web Developers

Paul Booker: Programmatically adding terms into a vocabulary from a structured text file

Posted on Wednesday, November 26th, 2014 by Anonymous
/**
    * Implements hook_install().
    */
function artist_install() { 
  artist_install_vocabularies();  
  artist_install_terms();
}

 /**
    * Installs artist module's default terms that are read from
    * text files in the module's includes folder.
    */
function artist_install_terms() {
  foreach (array_keys(artist_vocabularies()) as $machine_name) {
    $v = taxonomy_vocabulary_machine_name_load($machine_name);
    $wrapper = entity_metadata_wrapper('taxonomy_vocabulary', $v);

    if ($wrapper->term_count->value() == 0) {
      $path = drupal_get_path('module', 'artist') . '/includes/terms_' . $v->machine_name . '.txt';
      $lines = file($path, FILE_SKIP_EMPTY_LINES);
      artist_install_term_tree($wrapper, $lines);
    } 
  }
}

/**
 * Installs a term tree.

Paul Booker: Programmatically adding terms into a vocabulary from a structured text file

Posted on Wednesday, November 26th, 2014 by Anonymous
/**
    * Implements hook_install().
    */
function artist_install() { 
  artist_install_vocabularies();  
  artist_install_terms();
}

 /**
    * Installs artist module's default terms that are read from
    * text files in the module's includes folder.
    */
function artist_install_terms() {
  foreach (array_keys(artist_vocabularies()) as $machine_name) {
    $v = taxonomy_vocabulary_machine_name_load($machine_name);
    $wrapper = entity_metadata_wrapper('taxonomy_vocabulary', $v);

    if ($wrapper->term_count->value() == 0) {
      $path = drupal_get_path('module', 'artist') . '/includes/terms_' . $v->machine_name . '.txt';
      $lines = file($path, FILE_SKIP_EMPTY_LINES);
      artist_install_term_tree($wrapper, $lines);
    } 
  }
}

/**
 * Installs a term tree.

Paul Booker: Programmatically adding terms into a vocabulary from a structured text file

Posted on Wednesday, November 26th, 2014 by Anonymous
/**
    * Implements hook_install().
    */
function artist_install() { 
  artist_install_vocabularies();  
  artist_install_terms();
}

 /**
    * Installs artist module's default terms that are read from
    * text files in the module's includes folder.
    */
function artist_install_terms() {
  foreach (array_keys(artist_vocabularies()) as $machine_name) {
    $v = taxonomy_vocabulary_machine_name_load($machine_name);
    $wrapper = entity_metadata_wrapper('taxonomy_vocabulary', $v);

    if ($wrapper->term_count->value() == 0) {
      $path = drupal_get_path('module', 'artist') . '/includes/terms_' . $v->machine_name . '.txt';
      $lines = file($path, FILE_SKIP_EMPTY_LINES);
      artist_install_term_tree($wrapper, $lines);
    } 
  }
}

/**
 * Installs a term tree.

Pages

Subscribe to UNI Webtools: Resources for Web Developers RSS