Unable to retrieve token [current-user:roles:last]

Created on 6 September 2023, 10 months ago
Updated 16 October 2023, 9 months ago

In version 2.0.0 it works very well. See, 2.0.0.png

But in version 2.0.1 nothing is returned. See, 2.0.1.png

The token is used in a context filter. See, contextual filter.png

THANKS

🐛 Bug report
Status

Closed: duplicate

Version

2.0

Component

Code

Created by

🇫🇷France thfalvar

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

Comments & Activities

  • Issue created by @thfalvar
  • 🇮🇳India sumit-k

    It appears that the issue encountering is related to the [current-user:roles:last] token not being supported because roles:last is not a valid field name within the user entity.

    public function processToken(FieldableEntityInterface $entity, $token_entity_type, $argument) {
        // @todo $entity_type could potentially be retrieved by checking on $entity.
        $and_or = $this->options['and_or'];
        $field_names = $this->tokenScan($argument);
        foreach ($field_names[$token_entity_type] as $field_name => $token) {
          $replace_values = [];
          if ($entity->hasField($field_name)) {
            $field_values = $entity->get($field_name)->getValue();
            foreach ($field_values as $field_value) {
              $replace_values[] = array_values($field_value)[0];
            }
    
            // Replace and implode with , or + for multiple value management.
            $replace = implode($and_or, $replace_values);
            $argument = str_replace($token, $replace, $argument);
          }
        }
        return $argument;
      }

    The provided code snippet shows the processToken function in Drupal, which handles token replacement within entities. In this function, it attempts to retrieve the field values associated with the specified field name from the entity. However, it checks if the entity has a field with the name roles:last, and since this field name does not exist within the user entity, the token replacement does not occur.

  • 🇫🇷France thfalvar

    ok, but then why does this work in 2.0.0 ?

  • 🇺🇸United States rudy.barrett

    I'm running into this issue on a few of my sites and have had to subsequently roll back to 2.0.0 in order to get them to work again. Specifically, it seems to be related to this commit.
    https://git.drupalcode.org/project/views_argument_token/-/commit/8732825...

    That one commit breaks many of my sites' contextual filters.

  • 🇨🇦Canada smulvih2 Canada 🍁

    @rudy I think I am having the same issue on one of my sites. Will test removing this patch to see if it resolves the issue.

  • Status changed to Closed: duplicate 9 months ago
  • 🇨🇦Canada smulvih2 Canada 🍁

    Marking as duplicate of original issue.

Production build 0.69.0 2024