Skip to content

Commit

Permalink
Conditional IoR admin links (IoR roles only)
Browse files Browse the repository at this point in the history
  • Loading branch information
patschilf committed Mar 11, 2024
1 parent d118e74 commit bf0fe9a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
13 changes: 13 additions & 0 deletions custom/modules/ior/ior.links.menu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
system.admin.unblib.ior:
title: Images of Research
description: 'Manage Images of Research contests'
route_name: 'view.ior_contests.page_1'
parent: system.admin.unblib
weight: 100

system.admin.unblib.ior.contest:
title: Contests
description: 'Manage contests'
route_name: 'view.ior_contests.page_1'
parent: system.admin.unblib.ior
weight: 0
20 changes: 20 additions & 0 deletions custom/modules/ior/ior.module
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,23 @@ function ior_update_9004(&$sandbox) {
->fields(['bundle' => 'image'])
->execute();
}

/**
* Implements hook_menu_links_discovered_alter().
*/
function ior_menu_links_discovered_alter(&$links) {
$user = Drupal::service(('current_user'));
$ior_roles = array_filter($user->getAccount()->getRoles(), function ($role) {
return $role === 'ior_manager' || $role === 'ior_reviewer';
});

if (!count($ior_roles)) {
$ior_link_ids = array_filter(array_keys($links), function ($link_id) {
return preg_match("/^system.admin.unblib.ior/", $link_id);
});

foreach ($ior_link_ids as $link_id) {
unset($links[$link_id]);
}
}
}

0 comments on commit bf0fe9a

Please sign in to comment.