From fda736be6f830d900f3489faf50ab63af4d480e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 7 Jan 2026 11:14:27 +0100 Subject: [PATCH] can use an extrafield value in filter (#36822) --- htdocs/core/class/extrafields.class.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 9d411eb916e..1b3935367e2 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -9,7 +9,7 @@ * Copyright (C) 2015-2025 Charlene BENKE * Copyright (C) 2016 Raphaël Doursenaud * Copyright (C) 2017 Nicolas ZABOURI - * Copyright (C) 2018-2025 Frédéric France + * Copyright (C) 2018-2026 Frédéric France * Copyright (C) 2022 Antonin MARCHAL * Copyright (C) 2024-2025 MDW * Copyright (C) 2024 Benoît PASCAL @@ -1586,16 +1586,24 @@ class ExtraFields $InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]); } - // can use filter on any field of object + // can use filter on any field of object or in array_options if (is_object($object)) { $tags = []; preg_match_all('/\$(.*?)\$/', $InfoFieldList[4], $tags); // Example: $InfoFieldList[4] is ($dateadh$:<=:CURRENT_DATE) foreach ($tags[0] as $keytag => $valuetag) { $property = preg_replace('/[^a-z0-9_]/', '', strtolower($tags[1][$keytag])); - if (strpos($InfoFieldList[4], $valuetag) !== false && property_exists($object, $property) && !empty($object->$property)) { - $InfoFieldList[4] = str_replace($valuetag, (string) $object->$property, $InfoFieldList[4]); + if (strpos($property, 'options_') === 0) { // Example: $InfoFieldList[4] is ($options_dateadh$:<=:CURRENT_DATE) if options_datadh is an extrafield + if (strpos($InfoFieldList[4], $valuetag) !== false && isset($object->array_options[$property]) && !empty($object->array_options[$property])) { + $InfoFieldList[4] = str_replace($valuetag, (string) $object->array_options[$property], $InfoFieldList[4]); + } else { + $InfoFieldList[4] = str_replace($valuetag, '0', $InfoFieldList[4]); + } } else { - $InfoFieldList[4] = str_replace($valuetag, '0', $InfoFieldList[4]); + if (strpos($InfoFieldList[4], $valuetag) !== false && property_exists($object, $property) && !empty($object->$property)) { + $InfoFieldList[4] = str_replace($valuetag, (string) $object->$property, $InfoFieldList[4]); + } else { + $InfoFieldList[4] = str_replace($valuetag, '0', $InfoFieldList[4]); + } } } }