Skip to content

Conversation

swierczek
Copy link
Contributor

Add {exp:member:role_groups} template tag to get info about which Role Groups a member is assigned to.

Documentation will still be needed if this is accepted, which I am happy to update too. I didn't want to do all of the work if this will be declined by the mods though.

Demo template:

{!-- existing functionality --}
<h1>Roles</h1>
{exp:member:roles}
	<p>role ID: {role_id}</p>
	<p>role name: {name}</p>
{/exp:member:roles}

{!-- new functionality --}
<h1>Role Groups</h1>
{exp:member:role_groups}
	<p>role group id: {role_group_id}</p>
	<p>role group name: {role_group_name}</p>
{/exp:member:role_groups}

Output for member not assigned to any Role Groups:
image

Output for member in a Role Group:
image

Copy link
Contributor

@intoeetive intoeetive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@swierczek I think it's good addition! We're planning to roll out some Member functionality updates in 7.4, so it might go there as well.

I added a couple of comments, and also the code needs to be made PSR-12 compatible (e.g. a space is needed after foreach)

}

$vars = [];
foreach($member->RoleGroups->asArray() as $roleGroup) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a specific reason to call asArray here? RoleGroups is already iterable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, I didn't realize it was iterable 👍

];
};

if (!$vars) {
Copy link
Contributor

@intoeetive intoeetive Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Casting array to boolean is not PHP-version-proof. It should be better to use empty() check instead

@intoeetive intoeetive added this to the 7.4.0 milestone Aug 16, 2023
@intoeetive intoeetive added docs covered Has User Guide PR, or no documentaion necessary and removed needs documentation labels Oct 25, 2023
@intoeetive intoeetive changed the title Add {exp:member:role_groups} template tag Added {exp:member:role_groups} template tag Oct 25, 2023
@intoeetive intoeetive changed the base branch from 7.dev to release/7.4.0 November 8, 2023 10:29
@intoeetive intoeetive merged commit e9275ca into ExpressionEngine:release/7.4.0 Nov 8, 2023
@robinsowell robinsowell self-assigned this Nov 13, 2023
@matthewjohns0n matthewjohns0n self-assigned this Nov 13, 2023
@matthewjohns0n
Copy link
Member

This tag isnt working for me - I'm testing with a super admin account and have one role group called "all" which contains all roles.

This is the output of the example template tag:
Screenshot 2023-11-15 at 3 48 38 PM

When I dig into the code, I'm seeing that during the loop, $roleGroup->group_id is 0 and it hits the continue. I'm not sure why I'm not getting the correct role groups here.

];
};

if (!empty($vars)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be inverted - fixed here: f8bf5ac

@matthewjohns0n
Copy link
Member

After the above fix, it is parsing it as if there is no member role group. This is still incorrect because I should have one member role group.

Current output:

Screenshot 2023-11-15 at 3 57 12 PM

@intoeetive
Copy link
Contributor

It appears that besides member roles assigned to groups, role groups can be assigned directly to members (don't ask me why! :) - although you can't assign those directly to superadmins.

The template code was only respecting the second, and not the first - so I added that.

@matthewjohns0n please re-test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs covered Has User Guide PR, or no documentaion necessary enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants