You are here

protected function CslReferenceNormalizer::extractFields 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::extractFields()

Extract fields values from reference entity.

Parameters

\Drupal\bibcite_entity\Entity\ReferenceInterface $reference: Reference entity object.

string $format: Serializer format.

Return value

array Array of entity values.

Overrides ReferenceNormalizerBase::extractFields

File

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

Class

CslReferenceNormalizer
Normalizes/denormalizes reference entity to CSL format.

Namespace

Drupal\bibcite_entity\Normalizer

Code

protected function extractFields(ReferenceInterface $reference, $format = NULL) {
  $attributes = [];
  $attributes['title'] = $this
    ->extractScalar($reference
    ->get('title'));
  foreach ($this->fieldsMapping[$this->format] as $csl_field => $entity_field) {
    if ($entity_field && $reference
      ->hasField($entity_field) && ($field = $reference
      ->get($entity_field)) && !$field
      ->isEmpty()) {
      if (in_array($entity_field, $this->dateFields)) {
        $attributes[$csl_field] = $this
          ->extractDate($field);
      }
      else {
        $attributes[$csl_field] = $this
          ->extractScalar($field);
      }
    }
  }
  return $attributes;
}