How to loop through all roles

Created on 1 August 2023, over 1 year ago
Updated 2 August 2023, over 1 year ago

Hello, I need to create an ECA model that will check each role from the available ones and assign different values based on the role. How can I do this correctly? Thank you.

πŸ’¬ Support request
Status

Fixed

Version

1.2

Component

Documentation

Created by

πŸ‡ΊπŸ‡¦Ukraine Sharik_2023

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

Comments & Activities

  • Issue created by @Sharik_2023
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    The best way to do that is by creating a view to receive all roles and then loop through the list of roles. Examples for that can be found in the ECA Guide under the #views tag, see https://ecaguide.org/tags/#views - there are 5 examples that do things like that.

    As roles are config entities, and not content entities, views don't support them out of the box. But with a module like Configuration Views β†’ that shouldn't be a problem.

  • πŸ‡ΊπŸ‡¦Ukraine Sharik_2023

    Thank you for the response, but can it be done through a condition: "Role of user" or "Compare two scalar values"?

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

    I don't understand the requirement. Originally you asked how you can do something for all available roles. Now you want to just go through all the roles of the current user? Yes, that's also possible, if that's what you're looking for. You can get all roles of a user as a list and loop through them, just like described above. You can find the token with all the roles of a user in the token browser.

  • πŸ‡ΊπŸ‡¦Ukraine Sharik_2023

    Sorry for the imprecise question. The task is to ensure that after the user registers, there is a condition that each role should have a different field value. For example, for 'Jun' - 7 days, for 'Mid' - 9 days.

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

    I don't know what that means. I'm sure you can do all you're looking for. There are all the conditions and actions available to check, get and set values. What exactly are you missing?

  • πŸ‡ΊπŸ‡¦Ukraine Sharik_2023

    Okay, please tell me which token should I write here?

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

    The token, that contains the user entity that you would like to check. If this is about the current user, then you can always use [user]. If it's about a different user, you need to load that user entity into token first, and then you use that token instead.

    Maybe watching some of the videos on how to do certain things with ECA might be helpful. You can find them here: https://tube.tchncs.de/c/eca/videos

  • πŸ‡ΊπŸ‡¦Ukraine Sharik_2023

    Thank you, it worked out!

  • Status changed to Fixed over 1 year ago
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024