public function Field::getSynonyms in Synonyms 8
Same name and namespace in other branches
- 2.0.x src/Plugin/Synonyms/Provider/Field.php \Drupal\synonyms\Plugin\Synonyms\Provider\Field::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/ Field.php, line 94
Class
- Field
- Provide synonyms from attached simple fields.
Namespace
Drupal\synonyms\Plugin\Synonyms\ProviderCode
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;
}