Search field_numero_facture too in the entrée-liée autocomplete

Several entrées for the same client often share the same title format
("EPAU - 2026-01-05"), so being able to type the invoice number itself
is what actually finds the right one quickly. buildEntityQuery()
withholds $match from the parent call (which would otherwise add its
own title-only condition) and applies it manually as an OR across title
and field_numero_facture instead.

Verified live: searching "F2549" (not present in the title at all, only
in field_numero_facture) now correctly surfaces that entrée; a
title-only search and a no-match search both still behave as before.
This commit is contained in:
2026-09-06 10:37:06 +02:00
parent b6540e56c7
commit 50a6432691
@@ -23,9 +23,16 @@ class EntreeClientSelection extends NodeSelection {
/**
* {@inheritdoc}
*
* Matches on title *or* field_numero_facture -- several entrées for the
* same client often share the same title format ("EPAU - 2026-01-05"),
* so being able to type the invoice number itself ("F2549") is what
* actually finds the right one quickly. $match is withheld from the
* parent call (it would otherwise add its own title-only condition)
* and applied manually below as an OR across both fields instead.
*/
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
$query = parent::buildEntityQuery($match, $match_operator);
$query = parent::buildEntityQuery(NULL, $match_operator);
$query->condition('field_type_ligne', 'entree');
$entity = $this->configuration['entity'] ?? NULL;
@@ -33,6 +40,14 @@ class EntreeClientSelection extends NodeSelection {
$query->condition('field_client', $entity->get('field_client')->target_id);
}
if (isset($match)) {
$query->condition(
$query->orConditionGroup()
->condition('title', $match, $match_operator)
->condition('field_numero_facture', $match, $match_operator)
);
}
return $query;
}