You are here

public function BiblioStyleBibtex::importContributors in Bibliography Module 7.3

Import contributors.

Parameters

EntityMetadataWrapper $wrapper: The wrapped Biblio object.

$entry: The data to import from.

1 call to BiblioStyleBibtex::importContributors()
BiblioStyleBibtex::importData in plugins/biblio_style/bibtex/BiblioStyleBibtex.class.php
@inheritdoc

File

plugins/biblio_style/bibtex/BiblioStyleBibtex.class.php, line 219
BibTeX style.

Class

BiblioStyleBibtex
@file BibTeX style.

Code

public function importContributors(EntityMetadataWrapper $wrapper, $entry) {
  foreach (array(
    'author',
    'editor',
  ) as $type) {
    if (empty($entry[$type])) {
      continue;
    }
    $biblio = $wrapper
      ->value();

    // Get array of saved contributor objects from string of names.
    $contributors = BiblioContributorUtility::getBiblioContributorsFromNames($entry[$type]);
    foreach ($contributors as $contributor) {

      // Create contributors field collections without saving them.
      // We do not save the field collections because the whole Biblio object
      // may not be saved if it is duplicate, and in that case we will have
      // field collections without a host. By not saving the field collections
      // here we make sure they will only be saved if and when the whole
      // Biblio is saved.
      $field_collection = entity_create('field_collection_item', array(
        'field_name' => 'contributor_field_collection',
      ));
      $field_collection
        ->setHostEntity('biblio', $biblio);
      $collection_wrapper = entity_metadata_wrapper('field_collection_item', $field_collection);
      $collection_wrapper->biblio_contributor
        ->set($contributor);

      // @todo: Add reference to correct term.
      $term = taxonomy_get_term_by_name(ucfirst($type), 'biblio_roles');
      $term = reset($term);
      $collection_wrapper->biblio_contributor_role
        ->set($term);
    }
  }
}