By Uwe Sunkel on Tuesday, 03 October 2017
Posted in General Issues
Replies 9
Likes 0
Views 414
Votes 0
Hi,

How can I hide some menu items for users with a certain profile type. Please have a look at the screenshot attached. I need to hide all items except "Edit Profile" and "Logout".

Regards,
Uwe
Hi Uwe,

From the screenshot, it looks like you are referring the the links in the toolbar dropdown. If that's the case, unfortunately these menu cannot be hidden based on profile types.

If you want to perform any template overrides to the file, you can refer to the toolbar's theme file.
Example for elegant theme:
JoomlaFolder/components/com_easysocial/themes/elegant/toolbar/default.php
·
Tuesday, 03 October 2017 16:53
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi Raymond,

Yes it is the toolbar dropdown. Template override is fine. Could you please give me a little assistance with the code? Eg. there is this piece of code in line 248-254


<?php if ($this->config->get('followers.enabled')) { ?>
<div class="<?php echo $view == 'followers' ? 'is-active' : '';?>">
<a href="<?php echo ESR::followers();?>">
<?php echo JText::_('COM_EASYSOCIAL_TOOLBAR_FOLLOWERS'); ?>
</a>
</div>
<?php } ?>


So all menu items are defined in default.php independently. It should be possible to add a validation check which profile type (basic or premium) or Joomla user group (also basic or premium) the user belongs to. If the user belongs to "basic" the menu item does not show. Otherwise it shows. How would I include this in default.php?

Thanks for your support!

Regards,
Uwe
·
Tuesday, 03 October 2017 17:30
·
0 Likes
·
0 Votes
·
0 Comments
·
Hey Uwe,

As mentioned earlier, the toolbar drop-down cannot be displayed based on profile types or user groups.

One alternative you can try is by not displaying those options in the drop-down altogether. Instead create your own menu items from Joomla's menu manager.

This is a great alternative because you can control the display of the menu items according to user groups(http://take.ms/xwg8i).
·
Tuesday, 03 October 2017 17:54
·
0 Likes
·
0 Votes
·
0 Comments
·
let me challenge this for a second ;-)

If I put something like this at the beginning of default.php



// ACL defintions

// Basic (usergroup is "basic")
if (in_array('1', $user->groups))
{
$basic = true;
}

// Premium (usergroup is "premium")
if (in_array('2', $user->groups))
{
$premium = true;
}


And then something like this in front of each menu item


<?php if($premium): ?>


then this should be possible - correct?

If I am wrong please correct me. I am not a php-expert. This is just based on very little knowledge ...
·
Tuesday, 03 October 2017 18:01
·
0 Likes
·
0 Votes
·
0 Comments
·
Hey Uwe,
You can use the getProfile function to get the profile type of the current logged in user.
Below is an example to check the profile type id of the current user.

$myProfile = $this->my->getProfile()->id;
// ACL defintions
$basic = false;
$premium = false;
// Basic (profile type is "basic")
if ($myProfile == 1) {
$basic = true;
}

// Premium (profile type is "premium")
if ($myProfile == 2) {
$premium = true;
}
If you only have 2 profile types, you can just specify the rest as basic.
·
Tuesday, 03 October 2017 19:12
·
0 Likes
·
0 Votes
·
0 Comments
·
Great! We are getting closer :-) And then in front of any menu item I put


<?php if($premium): ?>


and behind


<?php endif; ?>


Seems to be working. I will test!
·
Tuesday, 03 October 2017 19:34
·
0 Likes
·
0 Votes
·
0 Comments
·
Alright Uwe.
·
Tuesday, 03 October 2017 19:37
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post