Expected [session_user] token missing

Created on 11 July 2024, about 2 months ago
Updated 23 July 2024, about 2 months ago

Problem/Motivation

I'm finding that I can't access the expected [session_user] token(s). I was on 2.0.0.-rc1 when I discovered this, but the issue remains after trying in 2.0.0 and 2.0.x-dev. To test, I simplified my model to just the Event and a "Display Message" Action (making sure to replace tokens).

In my main use case, the Event selected is a "Submit Form" and this results in other tokens that DO work:

In my sample troubleshooting text, I get a result like the following:

form:id: gps_proxy_form
form:base_id:
form:operation:
form:mode:
form:triggered: submit
form:values:lookup_id: 5590785
form:values:session_title: New June Session
form:num_errors:
event: machine_name: eca.form.submit
event:machine_name: eca.form.submit
session_user:
session_user:account-name:
session_user:uid:
session_user:id:

Because my use case specifically involves switching users in the same model, I require the [session_user] as promised to be different from the [current_user], and as a further test, I created a new model to display a similar message upon viewing a node. Once again, the [session_user] tokens fail, but the [current_user] tokens work as expected (including while masquerading as another user, in which case THAT user is shown).

Steps to reproduce

Pick an Event to trigger a new Model (in my case, a custom form defined in a module, but as noted, this appears to be a problem with other scenarios, too), create a new ECA model to trigger in the "Submit Form" event, restricted to the id of the form. Add a "Display Message" action and enter troubleshooting text borrowed from the form_form_submit documentation such as:

form:id: [form:id]

form:base_id: [form:base_id]

form:operation: [form:operation]

form:mode: [form:mode]

form:triggered: [form:triggered]

form:values:lookup_id: [form:values:lookup_id]

form:values:session_title: [form:values:session_title]

form:num_errors: [form:num_errors]

event: [event]

event:machine_name: [event:machine_name]

session_user: [session_user]

session_user:account-name: [session_user:account-name]

session_user:uid: [session_user:uid]

session_user:id: [session_user:id]

Upon submitting the form to trigger the model, discover that some of the tokens aren't replaced as expected, specifically the [session_user]. I omitted some of the basic tokens that DO work, such as [form] and [form:values] to protect some data, but sample form fields are shown as a confirmation that not everything is broken.

πŸ“Œ Task
Status

Active

Version

2.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States Glottus

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

Comments & Activities

  • Issue created by @Glottus
  • πŸ‡ΊπŸ‡ΈUnited States Glottus

    My second test (triggered by a simple entity view) has a similar result:

    event: machine_name: eca.content_entity.view
    event:machine_name: eca.content_entity.view
    session_user:
    session_user:account-name:
    session_user:uid:
    session_user:id:
    current_user: 7
    current_user:account-name: harri740
    current_user:uid: 7
    current_user:id:

    In this case, I'm actually logged in as user 1 and masquerading under my personal account, which is correctly reflected under the [current_user] tokens, but the [session_user] still is not. To do this "the ECA way", I further modified this model to switch user to my personal account before displaying the message and re-triggered it as user 1 again (not masquerading), and the results were identical to the above.

  • πŸ‡ΊπŸ‡ΈUnited States Glottus

    UPDATE:

    Never mind. Egg on my face, as I discovered buried under the ECA Settings an indication that [session_user] might only be available if I configured ECA to always run under a specific account. I had not done that (yet), and found that indeed this worked as advertised.

    Perhaps this could be highlighted a bit more in the documentation? Or else maybe make the [session_user] ALWAYS available (especially as a feature when the "Switch User" Action is used)?

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Thanks @Glottus for reporting this and then even finding the "resolution".

    I agree, we should improve the documentation of the session_user token which can be done in the attributes for the \Drupal\eca\EventSubscriber\EcaExecutionSwitchAccountSubscriber::onBeforeInitialExecution method. Happy to review an MR, if anyone could get around to that.

    Using the same token for the switch user action isn't possible, I guess. This is because that action could be called several times, not only once.

Production build 0.71.5 2024