You are here

protected function LinkFieldSerializer::getFieldTranslations in Acquia Content Hub 8.2

Extracts all translations of field.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: Entity.

\Drupal\acquia_contenthub\Event\SerializeCdfEntityFieldEvent $event: The content entity field serialization event.

Return value

\Drupal\Core\Field\FieldItemListInterface[] List of fields.

1 call to LinkFieldSerializer::getFieldTranslations()
LinkFieldSerializer::onSerializeContentField in src/EventSubscriber/SerializeContentField/LinkFieldSerializer.php
On serialize content field event function.

File

src/EventSubscriber/SerializeContentField/LinkFieldSerializer.php, line 157

Class

LinkFieldSerializer
Link Field Serializer.

Namespace

Drupal\acquia_contenthub\EventSubscriber\SerializeContentField

Code

protected function getFieldTranslations(ContentEntityInterface $entity, SerializeCdfEntityFieldEvent $event) {
  $fields = [];
  $languages = $entity
    ->getTranslationLanguages();
  $field = $event
    ->getField();
  if ($field
    ->getFieldDefinition()
    ->isTranslatable()) {
    foreach ($languages as $language) {
      $translated = $entity
        ->getTranslation($language
        ->getId());
      $fields[] = $translated
        ->get($event
        ->getFieldName());
    }
  }
  else {
    $fields[] = $field;
  }
  return $fields;
}