You are here

public function BaseField::getSynonyms in Synonyms 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Synonyms/Provider/BaseField.php \Drupal\synonyms\Plugin\Synonyms\Provider\BaseField::getSynonyms()

Fetch synonyms from an entity.

Parameters

Drupal\Core\Entity\ContentEntityInterface $entity: Entity whose synonyms should be fetched.

Return value

string[] Array of extracted synonyms

Overrides SynonymsGetTrait::getSynonyms

File

src/Plugin/Synonyms/Provider/BaseField.php, line 90

Class

BaseField
Provide synonyms from base fields.

Namespace

Drupal\synonyms\Plugin\Synonyms\Provider

Code

public function getSynonyms(ContentEntityInterface $entity) {
  $map = $this->fieldTypeToSynonyms
    ->getSimpleFieldTypeToPropertyMap();
  $field_type = $entity
    ->getFieldDefinition($this
    ->getPluginDefinition()['field'])
    ->getType();
  $synonyms = [];
  if (isset($map[$field_type])) {
    foreach ($entity
      ->get($this
      ->getPluginDefinition()['field']) as $item) {
      $synonyms[] = $item->{$map[$field_type]};
    }
  }
  return $synonyms;
}