default contextual filter token value output breaks at '<=' comparison

Created on 28 April 2021, almost 4 years ago
Updated 13 February 2025, 11 days ago

Problem/Motivation

Summary:
I am trying and failing to create a contextual filter for geofield proximity according to guidelines in this post: https://www.drupal.org/project/geofield/issues/3149688 . It is relying on this module for the default token value as [node:tokenvalue]<=20km.

The issue is that the token string is being truncated at the <= so the comparison is not being made I dont know if this is a bug with this module or an issue with the geofield module. I've enabled views_contextual_filter>default_value>show_debug option to see the output, which is breaking at the comparison < character.

debug message output
actual: 51.381257,-2.359984
expected: 51.381257,-2.359984 <= 20km

This is clearly chopping the token string at <=

If I remove the comparison operator and change the views default contextual filter token value to

[node:field_origin:latlon] 20km

this provides a debug output of

51.497296,-2.623011 20km

this is not sufficient for the comparison to work but does indicate a potential problem with inclusion of the "<=" operator

Steps to reproduce

I have tried to start from here:
https://www.drupal.org/project/geofield/issues/3149688

Proposed resolution

Special character combinations should be supported or documentation provided to explain how to include conditional statements in token replacements.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom Syntapse

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇩🇰Denmark ressa Copenhagen

    Just confirming that you still need to replace the "less than" < and "bigger than" > characters with HTML entities &lt; and &gt; in version 2. = by itself seems to work as is.

    This doesn't work: [node:field_map_position:latlon]<10km
    This works: [node:field_map_position:latlon]&lt;10km

    I spent a lot of time trying to get #3149688: Geofield Proximity Filter from Node/Entity being viewed (guidelines) working, and thanks for sharing the tip in #3139155-15: Drupal 9 Deprecated Code Report @rafaticarte, it really helped me :)

  • 🇩🇰Denmark ressa Copenhagen

    Another tip: It seems like you can't test a block in the view by entering an argument, like the node id here:

    Preview

    Auto preview
    Preview with contextual filters:
    [ ]
    Separate contextual filter values with a "/". For example, 40/12/10.

    You have to place the block and test it, actually placed in the context, i.e. on a node page.

  • 🇪🇸Spain rafaticarte

    Hi,

    I use PHP code in contextual filter:

    if (isset($entity['node'])) {
      $geofield = $entity['node']->field_activity_coordinates->getValue();
      if (isset($geofield[0])) {
        return $geofield[0]['lat'] . ',' . $geofield[0]['lon'] . '<10km'; 
      }
    }

    I hope this can help you.

  • 🇩🇰Denmark ressa Copenhagen

    Thanks! The method in #9 works well, with this method:

    Contextual filters >
    Content: Map Proximity (field_map_position) (Default: Token) >
    When the filter value is NOT available >
    Provide default value >
    Token >
    ... and then enter the string: [node:field_map_position:latlon]&lt;10km

    How would someone use the code you shared, and what would be the benefits over using the Views Argument Token solution outlined above?

  • 🇩🇰Denmark ressa Copenhagen

    Adding related issue.

Production build 0.71.5 2024