Skip to content

Commit c73f790

Browse files
authored
[4.4] Fix SQL field, get the filter value from the linked filter field (joomla#43789)
* Fix SQL field, get the filter value from the linked filter field * cs * esc ---------
1 parent 789ed19 commit c73f790

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

libraries/src/Form/Field/SqlField.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,21 @@ protected function processQuery($conditions, $filters, $defaults)
233233

234234
// Process the filters
235235
if (\is_array($filters)) {
236-
$html_filters = Factory::getApplication()->getUserStateFromRequest($this->context . '.filter', 'filter', [], 'array');
236+
// @TODO: Loading the filtering value from the request need to be deprecated.
237+
$html_filters = $this->context ? Factory::getApplication()->getUserStateFromRequest($this->context . '.filter', 'filter', [], 'array') : false;
238+
$form = $this->form;
237239

238240
foreach ($filters as $k => $value) {
239-
if (!empty($html_filters[$value])) {
241+
// Get the filter value from the linked filter field
242+
$filterFieldValue = $form->getValue($value, $this->group);
243+
244+
if ($html_filters && !empty($html_filters[$value])) {
240245
$escape = $db->quote($db->escape($html_filters[$value]), false);
241246

247+
$query->where("{$value} = {$escape}");
248+
} elseif ($filterFieldValue !== null) {
249+
$escape = $db->quote($db->escape($filterFieldValue), false);
250+
242251
$query->where("{$value} = {$escape}");
243252
} elseif (!empty($defaults[$value])) {
244253
$escape = $db->quote($db->escape($defaults[$value]), false);

0 commit comments

Comments
 (0)