From drupal.org on /node/2122241:
Altering menu links and adding menu links dynamically
Statically defined menu items may be altered using
hook_menu_links_discovered_alter() (but note there is no
hook_menu_link_discovered(), the menu links are built from the .yml
files as explained above). This hook may also be used to add new
dynamic menu items.
More often, you may want to use a deriver class to add new menu link
plugins. For example Views provided menu links are added in
views.links.menu.yml, which specifies the deriver class
\Drupal\views\Plugin\Derivative\ViewsMenuLink.
Finally, you can use the plugin manager directly to add, update, and
remove definitions.
You could probably use hook_menu_links_discovered_alter for your scenario.
Edit: You want to edit the permission to access that link, so it automatically does not show up in the menu.
Read on drupal.org: /node/2311427
Drupal 8
In Drupal 8, you can support dynamic permissions by referencing a
function that will dynamically define those permissions. This callback
defines the permissions for core's filter module.
// in filter.permissions.yml
permission_callbacks:
- Drupal\filter\FilterPermissions::permissions
// in FilterPermissions.php
class FilterPermissions {
public function permissions() {
$permissions = [];
// Generate permissions for each text format. Warn the administrator that any
// of them are potentially unsafe.
/** @var \Drupal\filter\FilterFormatInterface[] $formats */
$formats = $this->entityManager->getStorage('filter_format')->loadByProperties(['status' => TRUE]);
uasort($formats, 'Drupal\Core\Config\Entity\ConfigEntityBase::sort');
foreach ($formats as $format) {
if ($permission = $format->getPermissionName()) {
$permissions[$permission] = [
'title' => $this->t('Use the @label text format', ['@url' => $format->url(), '@label' => $format->label()]),
'description' => String::placeholder($this->t('Warning: This permission may have security implications depending on how the text format is configured.')),
];
}
}
return $permissions;
}
}
You should also read this article https://www.lullabot.com/articles/what-happened-to-hook_menu-in-drupal-8 (scroll down to "Access Control" and "Hook_Menu_Alter").
I hope this helps.
hook_translated_menu_link_alter() has been replaced by hook_menu_link_load()
, I do not know whether it is right or wrong, I just found this. Might be you can make out. If, let me also know.