You are here

public function BaseField::getSynonyms in Synonyms 2.0.x

Same name and namespace in other branches
  1. 8 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 GetInterface::getSynonyms

File

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

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) {
      if (!$item
        ->isEmpty()) {
        $synonyms[] = $item->{$map[$field_type]};
      }
    }
  }
  return $synonyms;
}