Tokens and Twig style variables are not replacement with values.
Instead of in the field stores something like that {{current_user->name}} or [current-user:name]

CommentFileSizeAuthor
#19 business_rules-2980052-18.patch1.04 KByseki
#16 example.jpg139.47 KBlexsoft00

Comments

wombatbuddy created an issue. See original summary.

wombatbuddy’s picture

Tokens and Twig variables also not working in "Show a message" Action.
For instance, if I paste into 'Message' field these tokens:
{{current_user}}
[current-date:short]
then the message display neither date nor user but only these tokens.

wombatbuddy’s picture

Title: Tokens and Twig style variables are not working in "Set values to entity variable" Action » Tokens and Twig style variables are not working in "Show a message" and "Set values to entity variable" Actions

  • yuriseki committed 1d24c63 on 8.x-1.x
    Issue #2980052 by wombatbuddy: Tokens and Twig style variables are not...
yseki’s picture

Assigned: Unassigned » yseki
Status: Active » Fixed

Hi @wombatbuddy,

The problem was on the Action, Condition and Variable processing. It was not keeping the token replaced values before the recursive call.
Thanks for reporting this issue.

It's committed on dev version.

c.e.a’s picture

Same problem here.

I have installed the dev version (updated on 9-Jul) and clear all caches.

However, if I paste into 'title' field of a content variable one of these tokens:
{{current_user->name}}
Or
[current-user:name]

then the output display is only these tokens as they are with no value replaced.

Thank you,

c.e.a’s picture

Status: Fixed » Needs review
c.e.a’s picture

Any update yet on this issue ?

[tokens] and {{tokens}} are not being replaced by real values even after using the dev version !!!

See below:

Images - step 1

Images - step 2

Images - step 3

Images - step 4 (Result)

Thank you,

  • yuriseki committed e35489f on 8.x-1.x
    Issue #2980052 by wombatbuddy, C.E.A, yuriseki: Tokens and Twig style...
yseki’s picture

Version: 8.x-1.0-alpha15 » 8.x-1.x-dev
Status: Needs review » Fixed

Thanks again C.E.A,

Despite the fact the main issue was solved, you are right, the context was not being passed to the token processor, and because of that, the webform title token was not being replaced.

It's on DEV now and by the end of today on ALPHA20.

yseki’s picture

Regarding the comment #2, {{current_user}} is not the correct way to use the variable. {{current_user}} is the container, you should use one of the following options:

  • {{current_user->uid}} User ID Number (integer)
  • {{current_user->uuid}} UUID UUID
  • {{current_user->langcode}} Language code Language
  • {{current_user->preferred_langcode}} Preferred language code Language
  • {{current_user->preferred_admin_langcode}} Preferred admin language code Language
  • {{current_user->name}} Name Text (plain)
  • {{current_user->pass}} Password Password
  • {{current_user->mail}} Email Email
  • {{current_user->timezone}} Timezone Text (plain)
  • {{current_user->status}} User status Boolean
  • {{current_user->created}} Created Created
  • {{current_user->changed}} Changed Last changed
  • {{current_user->access}} Last access Timestamp
  • {{current_user->login}} Last login Timestamp
  • {{current_user->init}} Initial email Email
  • {{current_user->roles}} Roles Entity reference
  • {{current_user->default_langcode}} Default translation Boolean
  • {{current_user->user_picture}} Picture Image

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

kenton.r’s picture

In a message no variable or token render during a "Entity field form alter." There are no errors. Just updated to the latest dev version. Any ideas why variables and tokens would not be processed? The variable from a view does not show at all.

the following are the variables and tokens tested
--------
[url:unaliased:args:1]
{{current_user->name}}
{{url_variable}}
[current-date:html_date]
{{current_series_id_and_uid->title}} --this is from a view that renders as a block on the page correctly
test
-------

They render as following:
------

{{current_user->name}}
{{url_variable}}
2019-03-28
{{current_series_id_and_uid->title}}
test
----------

for "Entity is viewed" it renders as:
------

Test Church
/winston-or
2019-03-28
{{current_series_id_and_uid->title}}
test
------

c.e.a’s picture

Status: Closed (fixed) » Needs work
c.e.a’s picture

The variables are not rendering when used inside "Set values to entity variable", for example try to set the text field of an entity equal to {{url_variable->1}} but you will receive the variable as it is with no processed value being replaced.

Note: Variables are being rendered correctly while used in "Show a message" action.

This is considered a critical bug report and actions must be taken asap.
this issue has been added to #3041221: List of all 'Bug reports' that need immediate support Assigned to: yseki.

lexsoft00’s picture

StatusFileSize
new139.47 KB

It works fine for me. Please find the image below as a representation of the test I've done. Could you try a custom variable instead of default variables?

Try to add an empty entity variable with user entity type and user bundle and use it in a "Set values to entity variable" action type.

c.e.a’s picture

Still have the same problem!

What I am doing in details:

RULE
Entity is viewed

  • Target Entity Type: User.
  • Target Bundle: User.

VARIABLE
Custom Empty Entity variable (logged_in_user_empty_entity_variable)

ACTIONS
1) Fetch entity variable by id.

  • Target Entity Type: User.
  • Target Bundle: User.
  • Variable: logged_in_user_empty_entity_variable
  • Value: 1

2) Set values to entity variable.

  • Target Entity Type: User.
  • Target Bundle: User.
  • Variable: logged_in_user_empty_entity_variable
  • Values: field_text_from_url = {{url_variable->1}}

3) Set entity variable.

  • Target Entity Type: User.
  • Target Bundle: User.
  • Variable: logged_in_user_empty_entity_variable

All the users url are converted to the path alias using the pathauto module like so:
/user/32 => /my-profile/john-smith/32

So logically, when any user will visit his profile, the value of the field (field_text_from_url) on my profile profile (uid:1) should be equal to: my-profile but currently all the value is: {{url_variable->1}}

Thank you,

  • yuriseki committed 96c0a54 on 8.x-1.x
    Issue #2980052 by lexsoft, C.E.A, wombatbuddy, yuriseki: Tokens and Twig...
yseki’s picture

Status: Needs work » Needs review
StatusFileSize
new1.04 KB

Hi @C.E.A,

I guess I got the issue. It worked on the scenario you've described.
The fix is already on DEV.

Here is the patch.

Thank you!

colan’s picture

Status: Needs review » Fixed

Marking as fixed for now. Please reopen if there are any problems.

c.e.a’s picture

The issue has been fixed and available in the beta-8 release and up.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.