Running into issues comparing multiple values with "=" at the end of the string

Created on 3 August 2023, over 1 year ago

Problem/Motivation

When using an entity field that contains multiple values that end in the equal sign (=) the concatenate values option seems to struggle parsing this and allowing the contextual filter to work correctly. I have tried using one value with the same configuration and the filter works as expected, as soon as there are two or more values, the filter stops working.

Steps to reproduce

Have a field with multiple values that end with an equal sign (=), set it as the entity field for the contextual filter. Remove the equal sign from the entity field and it works as expected.

Proposed resolution

I believe there is an issue with the = breaking the results when the concatenate option is selected.

Remaining tasks

I am going to look at the code and see if I can identify the issue and provide a patch. If anyone else can figure this out beforehand, please let me know.

🐛 Bug report
Status

Closed: works as designed

Version

2.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @pumpkinkid2
  • 🇨🇦Canada drclaw

    @pumpkinkid2 Interesting! I suspect that the values just need to be URL Encoded. My use cases for this module has typically been for referenced entity IDs so I haven't tested much with string values. On line 213 in CurrentEntityFieldValue.php, try changing

    $values = array_column($entity->{$field_name}->getValue(), $property);
    

    to

    $values = array_map('urlencode', array_column($entity->{$field_name}->getValue(), $property));
    

    And see if that gets you there!

  • Hi drclaw,

    Thank you for the quick response! I was actually looking at line 215 where the implode actually happens, however there may be a bit more to this as the change you suggested does not seem to resolve this.

    My use case is a bit odd, due to a custom module we are using to populate data automatically.

    We have two node types. One that has an entity reference field that contains a few entities and a multiple select value field that has reference IDs from a 3rd party system. This is the ID that has the = at the end of the value. The second node type just has a simple text field with the reference ID.

    I am using a relationship and listing information from the referenced entities, and attempting to use your module to filter out those whose reference ID does not match the values on the multiple select.

    I'm sure that was as clear as mud, so for now I am going to keep trying on my end and see if I just have the view misconfigured somewhere.

    I appreciate the help!

  • 🇨🇦Canada drclaw

    Oh yeah interesting. I think I follow. I'd maybe suggest inspecting the resulting SQL query to see what the IDs look like there. Maybe they're being transformed somewhere along the way and not transformed back correctly before being inserted into the query.

    Also, have you tried manually pasting one of the IDs into the views preview "Preview with contextual filters:" field? Might be good to see if the IDs work there or not. If they don't work there then it's probably an issue with views and not with this module.

  • Hmm, I'm starting to think this may have actually been an issue with views.

    When I use the two values with the equal sign, the query parses like this:
    ('blahblahblah=+blahblahblah2=')

    But when I remove the = I get:
    ('blahblahblah', 'blahblahblah2')

    Would you agree with my assessment?

  • I found an issue for views that explains exactly what I am seeing...

    https://www.drupal.org/project/drupal/issues/3034595#comment-15178526 🐛 Views contextual filters with multiple values do not work with arguments containing spaces Needs work

    Thanks for your help, but it looks like the problem is not related to this module.

  • Status changed to Closed: works as designed over 1 year ago
  • 🇨🇦Canada drclaw

    Ah perfect, nice find! And good to know!

    Thanks for reporting back. I'll close this issue down :)

Production build 0.71.5 2024