Skip to content
Snippets Groups Projects
Commit fa86cc20 authored by Karolina's avatar Karolina
Browse files

Issue #3469044 by karolinam, iwayMan: Add permission to translate links from the menu interface

parent bd1b06df
No related branches found
No related tags found
1 merge request!4Issue #3469044: Add permission to translate links from the menu interface
......@@ -82,6 +82,11 @@ function menu_perms_per_menu_form_menu_edit_form_alter(&$form, FormStateInterfac
unset($form['links']['links'][$menu_link_id]['operations']['#links']['delete']);
}
// Restrict access to 'Translate' in menu link operation dropdown.
if (!$account->hasPermission('translate links in ' . $menu->id() . ' menu from menu interface')) {
unset($form['links']['links'][$menu_link_id]['operations']['#links']['translate']);
}
// Restrict access to 'Add child' in menu link operation dropdown.
// Adding a child link is equivalent of creating/adding a new menu link.
if (!$account->hasPermission('add new links to ' . $menu->id() . ' menu from menu interface')) {
......
......@@ -40,6 +40,9 @@ class MenuPermsPerMenuPermissions {
$perms['edit link of menu links in ' . $menu->id() . ' menu'] = [
'title' => $this->t('Edit link of menu links in %menu menu', ['%menu' => $menu->label()]),
];
$perms['translate links in ' . $menu->id() . ' menu from menu interface'] = [
'title' => $this->t('Translate links in %menu menu from the menu interface', ['%menu' => $menu->label()]),
];
}
return $perms;
}
......@@ -77,4 +80,22 @@ class MenuPermsPerMenuPermissions {
return AccessResult::allowedIfHasPermission($account, 'delete links in ' . $menu_link_content->getMenuName() . ' menu from menu interface');
}
/**
* Checks access to menu item translation.
*
* @param \Drupal\Core\Session\AccountInterface $account
* Run access checks for this account.
* @param \Drupal\menu_link_content\Entity\MenuLinkContent $menu_link_content
* Run access checks for this menu link object.
*
* @return \Drupal\Core\Access\AccessResult
* The access result.
*/
public function translateItemAccess(AccountInterface $account, MenuLinkContent $menu_link_content = NULL) {
if (!$menu_link_content) {
return AccessResult::neutral();
}
return AccessResult::allowedIfHasPermission($account, 'translate links in ' . $menu_link_content->getMenuName() . ' menu from menu interface');
}
}
......@@ -34,6 +34,11 @@ class MenuPermsPerMenuRouteSubscriber extends RouteSubscriberBase {
$route->setRequirements(['_custom_access' => '\Drupal\menu_perms_per_menu\Access\MenuPermsPerMenuPermissions::deleteItemAccess']);
break;
case 'entity.menu_link_content.content_translation_overview':
case 'entity.menu_link_content.content_translation_add':
$route->setRequirements(['_custom_access' => '\Drupal\menu_perms_per_menu\Access\MenuPermsPerMenuPermissions::translateItemAccess']);
break;
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment