From 197b602b437ec1ac48a64c3863566e0354cf00b8 Mon Sep 17 00:00:00 2001 From: alisher372 Date: Sun, 2 Aug 2026 11:52:39 +0500 Subject: [PATCH] Fix Custom Dropdown filtering in table questions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When using GLPI Custom Dropdowns inside table questions, all dropdown definitions display the same combined list of values. This happens because all custom dropdowns use the same database table (`glpi_dropdowns_dropdowns`), but the current implementation does not apply the system criteria that distinguish each dropdown definition. ## Solution This change updates the table question implementation to correctly filter Custom Dropdown values by applying the item's `getSystemSQLCriteria()` when: - loading dropdown options; - resolving stored values. As a result, each Custom Dropdown now displays only the values that belong to its own definition. Before Снимок экрана 2026-07-21 143100 Снимок экрана 2026-07-21 143054 After Screenshot 2026-07-31 163806 Screenshot 2026-07-31 163809 --- src/Model/QuestionType/TableQuestion.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Model/QuestionType/TableQuestion.php b/src/Model/QuestionType/TableQuestion.php index 84889cf..84dc63f 100644 --- a/src/Model/QuestionType/TableQuestion.php +++ b/src/Model/QuestionType/TableQuestion.php @@ -553,11 +553,22 @@ private function resolveItemNames(string $itemtype, array $values): array global $DB; + $where = ['id' => $ids]; + + // GLPI 11 custom dropdown classes can share the same database table. + // Their system SQL criteria restrict rows to the current dropdown definition. + if (method_exists($itemtype, 'getSystemSQLCriteria')) { + $system_criteria = $itemtype::getSystemSQLCriteria(); + if (is_array($system_criteria) && $system_criteria !== []) { + $where[] = $system_criteria; + } + } + $map = []; foreach ($DB->request([ 'SELECT' => ['id', 'name'], 'FROM' => $item->getTable(), - 'WHERE' => ['id' => $ids], + 'WHERE' => $where, ]) as $row) { if (!is_array($row)) { continue; @@ -950,6 +961,15 @@ private function buildGlpiItemtypeOptions(string $itemtype): array $where = []; + // GLPI 11 custom dropdown classes can share the same database table. + // Their system SQL criteria restrict rows to the current dropdown definition. + if (method_exists($itemtype, 'getSystemSQLCriteria')) { + $system_criteria = $itemtype::getSystemSQLCriteria(); + if (is_array($system_criteria) && $system_criteria !== []) { + $where[] = $system_criteria; + } + } + if ($item->maybeDeleted()) { $where['is_deleted'] = 0; } @@ -998,4 +1018,4 @@ private function loadConfig(Question $question): TableQuestionConfig $config = $this->getExtraDataConfig($decoded); return $config instanceof TableQuestionConfig ? $config : new TableQuestionConfig(); } -} +} \ No newline at end of file