public function EntityReferenceSynonymsBehavior::extractSynonyms in Synonyms 7
Extract synonyms from an entity within a specific behavior implementation.
Parameters
object $entity: Entity from which to extract synonyms
string $langcode: Language code for which to extract synonyms from the entity, if one is known
Return value
array Array of synonyms extracted from $entity Array of synonyms extracted from $entity
Overrides SynonymsBehavior::extractSynonyms
File
- synonyms_provider_field/
includes/ EntityReferenceSynonymsBehavior.class.inc, line 13 - Enables Entity Reference field type to be source of synonyms.
Class
- EntityReferenceSynonymsBehavior
- Definition of EntityReferenceSynonymsBehavior class.
Code
public function extractSynonyms($entity, $langcode = NULL) {
$synonyms = array();
$target_tids = array();
foreach ($this
->entityItems($entity, $langcode) as $item) {
$target_tids[] = $item['target_id'];
}
$entities = entity_load($this->field['settings']['target_type'], $target_tids);
foreach ($entities as $entity) {
$synonyms[] = entity_label($this->field['settings']['target_type'], $entity);
}
return $synonyms;
}