0

I have an Entity select element that references a role. The element is unlimited so multiple users can be selected at one time. I need to get each selected user's email address.

Using a computed twig element, I can get the email address of the first selected user with webform_token():

{% set reviewer_email_address = webform_token('[webform_submission:values:reviewer:entity:mail]', webform_submission, [], options) %}
{{ reviewer_email_address }}

Something simple like:

{{ data.reviewer.0 }}
{{ data.reviewer.1 }}

prints the user id of the users. So the user entities are present.

How do I get the email address from {{ data.reviewer.0 }}?

1
  • You can use debugger and view data.reviewer variable. If you use twig tweak module you can use {{ drupal_breakpoint() }} for debug twig templates
    – Vanish
    Commented Sep 6, 2023 at 9:15

1 Answer 1

0

This is a non DRY solution:

{% set reviewer_0 = webform_token('[webform_submission:values:reviewer:0:entity:mail:clear]', webform_submission, [], options) %}
{% set reviewer_1 = webform_token('[webform_submission:values:reviewer:1:entity:mail:clear]', webform_submission, [], options) %}
{% set reviewer_2 = webform_token('[webform_submission:values:reviewer:2:entity:mail:clear]', webform_submission, [], options) %}
{% set reviewer_3 = webform_token('[webform_submission:values:reviewer:3:entity:mail:clear]', webform_submission, [], options) %}
{% set reviewer_4 = webform_token('[webform_submission:values:reviewer:4:entity:mail:clear]', webform_submission, [], options) %}
{% set reviewer_5 = webform_token('[webform_submission:values:reviewer:5:entity:mail:clear]', webform_submission, [], options) %}
{% if reviewer_0|length %}{{ reviewer_0 }}{% else %}{% endif %}
{% if reviewer_1|length %},{{ reviewer_1 }}{% else %}{% endif %}
{% if reviewer_2|length %},{{ reviewer_2 }}{% else %}{% endif %}
{% if reviewer_3|length %},{{ reviewer_3 }}{% else %}{% endif %}
{% if reviewer_4|length %},{{ reviewer_4 }}{% else %}{% endif %}
{% if reviewer_5|length %},{{ reviewer_5 }}{% else %}{% endif %}

with "Remove whitespace around the"
computed value and between HTML tags

and "Automatically update the computed value using Ajax".
Checked

in the computed twig element.

The twig needs to be improved in case there are more than 6 reviewers and for DRY principle.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.