function hook_graphql_term_autocomplete_query_alter in GraphQL 8.4
Alter the query built by the term autocomplete data producer.
Parameters
array $args: Input arguments of taxonomy term data producer.
\Drupal\Core\Database\Query\SelectInterface $query: The term autocomplete query.
\Drupal\Core\Database\Query\ConditionInterface $name_condition_group: The condition group matching the term name. This condition group is defined as OR condition group which allows to cover a match in term name OR in some other fields.
1 invocation of hook_graphql_term_autocomplete_query_alter()
- TermFieldAutocomplete::resolve in src/
Plugin/ GraphQL/ DataProducer/ Taxonomy/ TermFieldAutocomplete.php - Gets term items matched against given query for given vocabulary.
File
- ./
graphql.api.php, line 20 - Hooks provided by GraphQL module.
Code
function hook_graphql_term_autocomplete_query_alter(array $args, \Drupal\Core\Database\Query\SelectInterface $query, \Drupal\Core\Database\Query\ConditionInterface $name_condition_group) : void {
// Custom field on profile entity type of bundle resume has a reference to
// synonyms field. Extend a query so it matches the string in term names OR in
// synonyms.
if ($args['entity_type'] == 'profile' && $args['entity_type'] == 'resume' && ($args['field'] = 'field_custom')) {
$like_contains = '%' . $query
->escapeLike($args['match_string']) . '%';
$query
->leftJoin('taxonomy_term__field_term_synonyms', 's', 's.entity_id = t.tid');
// This makes the query to perform a match on term names OR synonyms.
$name_condition_group
->condition('s.field_term_synonyms_synonym', $like_contains, 'LIKE');
}
}