- Issue created by @robpowell
Out of the box Drupal will show menu UI on node edit if a role has the permission administer menu
. If a user has view the administer theme
the role will get the added benefit of seeing admin > structure > menu. This module now gives us granular control of what menus should be shown and how a user can interact with these menus.
One feature I feel is missing is the ability to see the menu UI on the node edit/create form. I feel like this is a pretty popular use case where you want a content creator to create content and assign it to a specific menu but you don't want them mucking about in the menu ui. Here is how I solved this locally but would love to see this as a future feature.
function foo_bar_form_node_form_alter(array &$form, FormStateInterface $form_state, string $form_id): void {
// Only check for simple menu perms if the user doesn't already have access.
if (!$form['menu']['#access']) {
// Get current user.
$user = \Drupal::currentUser();
$form['menu']['#access'] = !$user->hasPermission('add new links to main menu') ? AccessResult::forbidden() : AccessResult::allowed();
}
}
Active
3.0
Code