You are here

protected function CslReferenceNormalizer::extractAuthors in Bibliography & Citation 8

Same name and namespace in other branches
  1. 2.0.x modules/bibcite_entity/src/Normalizer/CslReferenceNormalizer.php \Drupal\bibcite_entity\Normalizer\CslReferenceNormalizer::extractAuthors()

Extract authors values from field.

Parameters

\Drupal\Core\Field\FieldItemListInterface $field_item_list: List of field items.

Return value

array Authors in CSL format.

Overrides ReferenceNormalizerBase::extractAuthors

File

modules/bibcite_entity/src/Normalizer/CslReferenceNormalizer.php, line 87

Class

CslReferenceNormalizer
Normalizes/denormalizes reference entity to CSL format.

Namespace

Drupal\bibcite_entity\Normalizer

Code

protected function extractAuthors(FieldItemListInterface $field_item_list) {
  $authors = [];
  foreach ($field_item_list as $field) {

    /** @var \Drupal\bibcite_entity\Entity\ContributorInterface $contributor */
    if ($contributor = $field->entity) {
      switch ($field->role) {
        case 'editor':
        case 'series_editor':
          $authors['editor'][] = [
            'category' => $field->category,
            'role' => $field->role,
            'family' => $contributor
              ->getLastName(),
            'given' => $contributor
              ->getFirstName() . ' ' . $contributor
              ->getMiddleName(),
            'suffix' => $contributor
              ->getSuffix(),
            'literal' => $contributor
              ->getName(),
          ];
          break;
        case 'recipient':
        case 'translator':
          $authors[$field->role][] = [
            'category' => $field->category,
            'role' => $field->role,
            'family' => $contributor
              ->getLastName(),
            'given' => $contributor
              ->getFirstName() . ' ' . $contributor
              ->getMiddleName(),
            'suffix' => $contributor
              ->getSuffix(),
            'literal' => $contributor
              ->getName(),
          ];
          break;
        default:
          $authors['author'][] = [
            'category' => $field->category,
            'role' => $field->role,
            'family' => $contributor
              ->getLastName(),
            'given' => $contributor
              ->getFirstName() . ' ' . $contributor
              ->getMiddleName(),
            'suffix' => $contributor
              ->getSuffix(),
            'literal' => $contributor
              ->getName(),
          ];
          break;
      }
    }
  }
  return $authors;
}