Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow DCA filter definitions without placeholder values #1257

Merged
merged 1 commit into from
Feb 7, 2020

Conversation

fritzmg
Copy link
Contributor

@fritzmg fritzmg commented Jan 28, 2020

In a project of ours we dynamically injected a DCA filter into

$GLOBALS['TL_DCA']['tl_foo']['list']['sorting']['filter']

via an onload_callback. However, in our case we wanted to add a query like this:

foo NOT IN (…)

Initially we added the filter like this:

$GLOBALS['TL_DCA']['tl_foo']['list']['sorting']['filter'][] = ['foo NOT IN ('.implode(',', $ids).')'];

However, since Contao assumes that these filters are always a placeholder/value pair, the placeholders and values will mismatch in the final query and thus it results in a wrong SQL query, when user defined filter is selected for example.

As a workaround we implemented it like this:

$GLOBALS['TL_DCA']['tl_foo']['list']['sorting']['filter'][] = ['(foo NOT IN ('.implode(',', $ids).') AND 1=?)', 1];

so that there is no placeholder/value mismatch anymore. But it would be convenient (and would save some debugging time …) if one could simply define a filter without a placeholder like this:

$GLOBALS['TL_DCA']['tl_foo']['list']['sorting']['filter'][] = 'foo NOT IN ('.implode(',', $ids).')';

This PR would allow that.

@leofeyer
Copy link
Member

I am fine with this change. We could even add it in Contao 4.9 IMHO. @contao/developers WDYT?

@leofeyer leofeyer added the bug label Jan 28, 2020
@leofeyer leofeyer added this to the 4.9 milestone Jan 28, 2020
@leofeyer
Copy link
Member

leofeyer commented Feb 4, 2020

@fritzmg Can you please rebase this PR onto the 4.9 branch?

@fritzmg fritzmg force-pushed the feature/dca-allow-filter-string branch from 189166f to 497a3ab Compare February 5, 2020 08:39
@fritzmg fritzmg changed the base branch from master to 4.9 February 5, 2020 08:40
@fritzmg
Copy link
Contributor Author

fritzmg commented Feb 5, 2020

Done 👍

@fritzmg
Copy link
Contributor Author

fritzmg commented Feb 5, 2020

The failing test does not seem to be related to this PR.

@leofeyer leofeyer merged commit 0ed5abf into 4.9 Feb 7, 2020
@leofeyer leofeyer deleted the feature/dca-allow-filter-string branch February 7, 2020 09:06
@leofeyer
Copy link
Member

leofeyer commented Feb 7, 2020

Thank you @fritzmg.

@leofeyer leofeyer changed the title DCA: allow definition of filter without placeholder values Allow DCA filter definitions without placeholder values Feb 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants