function synonyms_synonyms_find in Synonyms 7
Look up entities by their synonyms.
Parameters
QueryConditionInterface $condition: Object of QueryConditionInterface that specifies conditions by which you want to find synonyms. When building this condition object, you can use the following column placeholders:
- AbstractSynonymsBehavior::COLUMN_PLACEHOLDER: as a placeholder for real column name that contains synonym as text
- AbstractSynonymsBehavior::COLUMN_ENTITY_ID_PLACEHOLDER: as a placeholder for real column name that holds entity ID
For example, if you were to find all entities with synonyms that begin with "synonym-come-here" substring, case insensitive and replacing all spaces in original synonym string by a dash sign, then you would have to create the following condition object: db_and() ->where("LOWER(REPLACE(" . AbstractSynonymsBehavior::COLUMN_PLACEHOLDER . ", ' ', '-')) LIKE :synonym", array( ':synonym' => '%' . db_like($some-var) . '%' )) And then just supply this object as an input parameter to this function
string $entity_type: Among synonyms of what entity type to search
string|array $bundle: Optionally specify among synonyms of what bundle(-s) to search. You can specify here a string - bundle name to search within or an array of bundles within which to search
Return value
array Array of found synonyms and entity IDs to which those belong. Each element in the array will be an object and will have the following structure:
- synonym: (string) Synonym that was found and which satisfies the $condition you specified
- entity_id: (int) ID of the entity to which the found synonym belongs
5 calls to synonyms_synonyms_find()
- SynonymsSynonymsWebTestCase::testSynonyms in ./
synonyms.test - Test the functionality of synonyms.
- synonyms_get_entity_by_synonym in ./
synonyms.module - Try finding an entity by its name or synonym.
- synonyms_get_term_by_synonym in ./
synonyms.module - Try to find a term by its name or synonym.
- synonyms_term_synonyms_context in plugins/
arguments/ term_synonyms.inc - Discover if this argument gives us the term we crave.
- synonyms_views_plugin_argument_validate_taxonomy_term::validate_argument in views/
synonyms_views_plugin_argument_validate_taxonomy_term.inc
File
- ./
synonyms.module, line 791 - Provide synonyms feature for Drupal entities.
Code
function synonyms_synonyms_find(QueryConditionInterface $condition, $entity_type, $bundle = NULL) {
$rows = array();
$behavior_implementations = synonyms_behavior_get_all_enabled($entity_type, $bundle);
foreach ($behavior_implementations as $behavior_implementation) {
foreach ($behavior_implementation['object']
->synonymsFind(clone $condition) as $row) {
$rows[] = $row;
}
}
return $rows;
}