You are here

public function BibtexReferenceNormalizer::normalize in Bibliography & Citation 8

Same name and namespace in other branches
  1. 2.0.x modules/bibcite_bibtex/src/Normalizer/BibtexReferenceNormalizer.php \Drupal\bibcite_bibtex\Normalizer\BibtexReferenceNormalizer::normalize()

Overrides ReferenceNormalizerBase::normalize

File

modules/bibcite_bibtex/src/Normalizer/BibtexReferenceNormalizer.php, line 52

Class

BibtexReferenceNormalizer
Normalizes/denormalizes reference entity to BibTeX format.

Namespace

Drupal\bibcite_bibtex\Normalizer

Code

public function normalize($reference, $format = NULL, array $context = []) {

  /** @var \Drupal\bibcite_entity\Entity\ReferenceInterface $reference */
  $attributes = [];
  $attributes[$this->typeKey] = $this
    ->convertEntityType($reference
    ->bundle(), $format);
  if ($keywords = $this
    ->extractKeywords($reference
    ->get('keywords'))) {
    $attributes[$this->keywordKey] = $keywords;
  }
  $contributors = $this
    ->extractContributors($reference
    ->get('author'));
  if (isset($contributors['author'])) {
    $attributes[$this->contributorKey] = $contributors['author'];
  }
  if (isset($contributors['editor'])) {
    $attributes['editor'] = $contributors['editor'];
  }
  $attributes += $this
    ->extractFields($reference, $format);
  return $attributes;
}