function social_group_menu_local_tasks_alter in Open Social 8.4
Same name and namespace in other branches
- 8.9 modules/social_features/social_group/social_group.module \social_group_menu_local_tasks_alter()
- 8 modules/social_features/social_group/social_group.module \social_group_menu_local_tasks_alter()
- 8.2 modules/social_features/social_group/social_group.module \social_group_menu_local_tasks_alter()
- 8.3 modules/social_features/social_group/social_group.module \social_group_menu_local_tasks_alter()
- 8.5 modules/social_features/social_group/social_group.module \social_group_menu_local_tasks_alter()
- 8.6 modules/social_features/social_group/social_group.module \social_group_menu_local_tasks_alter()
- 8.7 modules/social_features/social_group/social_group.module \social_group_menu_local_tasks_alter()
- 8.8 modules/social_features/social_group/social_group.module \social_group_menu_local_tasks_alter()
- 10.3.x modules/social_features/social_group/social_group.module \social_group_menu_local_tasks_alter()
- 10.0.x modules/social_features/social_group/social_group.module \social_group_menu_local_tasks_alter()
- 10.1.x modules/social_features/social_group/social_group.module \social_group_menu_local_tasks_alter()
- 10.2.x modules/social_features/social_group/social_group.module \social_group_menu_local_tasks_alter()
Implements hook_menu_local_tasks_alter().
File
- modules/
social_features/ social_group/ social_group.module, line 826 - The Social group module.
Code
function social_group_menu_local_tasks_alter(&$data, $route_name) {
// Rename Group "Related Entities" tab.
if (isset($data['tabs'][0]['group.content']['#link'])) {
$data['tabs'][0]['group.content']['#link']['title'] = t('Manage members');
$data['tabs'][0]['group.content']['#weight'] = 70;
}
// Remove the default View tab.
if (isset($data['tabs'][0]['group.view'])) {
unset($data['tabs'][0]['group.view']);
}
// Remove Edit tab. Edit will always go through Floating Edit Button.
if (isset($data['tabs'][0]['group.edit_form'])) {
unset($data['tabs'][0]['group.edit_form']);
}
$user = \Drupal::currentUser();
// Get the Group object from the route.
$group = Drupal::routeMatch()
->getParameter('group');
if ($group instanceof GroupInterface) {
/** @var \Drupal\group\Entity\GroupTypeInterface $group_type */
$group_type = $group
->getGroupType()
->id();
// Check if it's a closed group.
if ($group_type === 'closed_group') {
// And if the user is not user 1.
if ($user
->id() !== 1) {
if ($user
->hasPermission('manage all groups')) {
return;
}
// If the user is not an member of this group.
if (!$group
->getMember($user)) {
// Disable these local tasks.
$data['tabs'][0]['group.view'] = [];
if (!$group
->hasPermission('administer members', $user)) {
$data['tabs'][0]['group.content'] = [];
}
$data['tabs'][0]['social_group.events'] = [];
$data['tabs'][0]['social_group.topics'] = [];
}
}
}
}
}