Accessing Joomla User Groups with Placeholders

Status
Not open for further replies.

softforge

Member
With the new ACL in J25, a user can now have many groups. Looking at the $user object, these groups are available in $user->groups so I expected to be able to access them with placeholders using the following:

{$my->groups}

However, this returns nothing and this is the reason why (parent.php around line 667):

PHP:
if (!is_object($val) && !is_array($val))
{
    $msg = str_replace('{$' . $prefix . '->' . $key . '}', $val, $msg);
    $msg = str_replace('{$' . $prefix . '->' . $key . '}', $val, $msg);
}

As the groups are returned as an array, they get ignored. I have made the following change to get a comma separated list of groups:

PHP:
if (!is_object($val) && !is_array($val))
{
    $msg = str_replace('{$' . $prefix . '->' . $key . '}', $val, $msg);
    $msg = str_replace('{$' . $prefix . '->' . $key . '}', $val, $msg);
}
elseif (is_array($val))
{
    $msg = str_replace('{$' . $prefix . '->' . $key . '}', implode(',', $val), $msg);
    $msg = str_replace('{$' . $prefix . '->' . $key . '}', implode(',', $val), $msg);
}

I can now manipulate the groups as I need so I have continued development with this approach. :)

I hope this change can make its way into Fabrik as I cant see any backwards compatibility issues and it it much easier to access the groups this way then to do a manual query.

Thanks for considering its inclusion! ;)
 
  • Like
Reactions: rob
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top