You are here

public function BiblioStyleBase::importKeywordsList in Bibliography Module 7.3

Helper function to import existing or new keywords.

Parameters

EntityMetadataWrapper $wrapper: The wrapped Biblio.

$property_name: The propery name. Defaults to "biblio_keywords".

array $keywords: Array of term names.

string $vocabulary_name: The vocabulary of the terms. Defaults to "biblio_keywords".

1 call to BiblioStyleBase::importKeywordsList()
BiblioStyleBibtex::importKeywords in plugins/biblio_style/bibtex/BiblioStyleBibtex.class.php
Import keywords.

File

plugins/biblio_style/abstract.inc, line 242

Class

BiblioStyleBase
An abstract implementation of MessageNotifierInterface.

Code

public function importKeywordsList(EntityMetadataWrapper $wrapper, $keywords = array(), $property_name = 'biblio_keywords', $vocabulary_name = 'biblio_keywords') {
  $terms = array();
  foreach ($keywords as $term_name) {
    if (!($term = taxonomy_get_term_by_name($term_name, $vocabulary_name))) {
      $vocabulary = taxonomy_vocabulary_machine_name_load($vocabulary_name);
      $values = array(
        'name' => $term_name,
        'vid' => $vocabulary->vid,
      );
      $term = entity_create('taxonomy_term', $values);
      taxonomy_term_save($term);
    }

    // taxonomy_get_term_by_name() returns an array, so normalize it.
    $terms[] = is_array($term) ? reset($term) : $term;
  }
  $wrapper->{$property_name}
    ->set($terms);
}