I've got a parent module that shows a list of functionality available from its sub modules. I'd like the links shown related to sub-modules to be added by the sub-modules themselves rather than being hard coded into the parent module (although they are generated using the route name).

The reason for this is so sub-modules are responsible for showing their functionality through the parent based on the users permissions and that work is self contained. Also means if a sub-module is disabled there won't be any dead links in the parent.

put on hold as unclear what you're asking by Kevin, Pierre.Vriens, Shawn Conn, Alfred Armstrong, mradcliffe Dec 7 at 1:13

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

This is an opportunity to create your own hook.

In the parent module, let's say the function responsible to provide the list of functionalities is your hook function.

In this function, you need to invoke modules providing the functionalities, thus meaning your submodules have to implement the hook in order to expose their features.

For example, in your main module :

/**
 * Shows a list of functionalities available from other modules
 */
function mainmodule_get_functionalities_list () {
  $list = \Drupal::moduleHandler()->invokeAll('list_functionalities');
  # Here filter the list based on user permissions, unless you have a good reason
  # to do it in each submodule (like if the permission is provided by the submodule, 
  # the parent may not be aware of it, or it means harcode). 
  return $list;
}

And in a submodule :

/**
 * Implements hook_functionalities_list
 */
function submodule_functionalities_list () {
  return [
    'some functionality',
    'awesome submodule functionality',
    #'etc.'
  ];
}

Note : hook_functionalities_list implementation is not restricted to submodules. If you really need to, you might want to invoke submodule "manually", that is : using \Drupal::moduleHandler()->getImplementations($hook);, filter the implementation list based on (sub)module naming, and foreach one make the call.

Not the answer you're looking for? Browse other questions tagged or ask your own question.