You can load all module defined menu links (i.e. links defined in *.menu.links.yml with the MenuLinkManager service's getDefinitions()
method and then parse the list for only links defined by your module.
$all_module_link_definitions = \Drupal::service('plugin.manager.menu.link')
->getDefinitions();
// Next parse the list for only links defined by my_module.
$my_module_link_definitions = [];
foreach ($all_module_link_definitions as $plugin_id => $plugin_definition) {
if ($plugin_definition['provider'] === 'MY_MODULE') {
$my_module_link_definitions[$plugin_id] => $plugin_definition;
}
}
Similarly, you can load all module defined local tasks with the LocalTaskManager service's getDefintions()
method and then parse the list for only tasks defined by your module.
$all_module_task_definitions = \Drupal::service('plugin.manager.menu.local_task')
->getDefinitions();
// Next parse the list for only tasks defined by my_module.
$my_module_task_definitions = [];
foreach ($all_module_task_definitions as $plugin_id => $plugin_definition) {
if ($plugin_definition['provider'] === 'MY_MODULE') {
$my_module_task_definitions[$plugin_id] => $plugin_definition;
}
}