Uh oh!
There was an error while loading. Please reload this page.
[4.x] Make contains modifier handle array needles - #8357
Conversation
Uh oh!
There was an error while loading. Please reload this page.
jasonvarga
commented
Jun 26, 2023
Are you sure? I don't believe that uses the modifier. |
ryanmitchell
commented
Jun 26, 2023
Forgot to push up the queriesConditions change - I blame @edalzell, he was rushing me |
jasonvarga
left a comment
There was a problem hiding this comment.
A test for the condition side of this would be very welcomed too. There's a QueriesConditionsTest class.
ryanmitchell
commented
Jun 26, 2023
No problem - added. Genuine question - is contains the right name/place for this? Going by the modifier it is, looking at queriesConditions I'm not so sure as its very string orientated. |
jasonvarga
commented
Jun 26, 2023
The functionality is probably fine, but you're right to question the naming. We should give this a little more thought. |
What if we named it |
ryanmitchell
commented
Sep 19, 2023
I think |
Oh yeah you're right, my apologies. |
jasonvarga
commented
Mar 6, 2024
Closing in favor of #9491 |
Sometimes you need to compare arrays to arrays, and it would be nice if the
containsmodifier was smart enough to handle it.This PR updates that modifier to check if the intersect count between the 2 arrays is greater than zero, and if so it's true. This allows you to do things like:
{{ collection:pages array_field:contains="this|or|that" }}or
{{ my_value | contains("this|or|that") }}Which people seem to assume should work (judging by discord).
I thought it better to do it this way rather than a new modifier.
You could argue it should be a strict comparison, where the intersect count needs to match the needle count, but this approach matches whereJsonContains, and I've updated the queriesConditions contains method too.