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.

closed as unclear what you're asking by Kevin, Pierre.Vriens, Shawn Conn, Alfred Armstrong, mradcliffe Dec 7 '18 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.

  • I have to agree with @EricLavault, I've not gotten back to the answer / marked as correct as I've been away and unable to implement to check it meets what is in my question. – Neil Nand Jan 4 at 9:14
  • So far, the post merely describes what you are trying to achieve, without making any explicit question, nor making clear what exactly you don't understand. The described task is too broad to be answered and the answer could be to implement an hook that is already used from a module, use a new hook, or use an event subscriber. – kiamlaluno Jan 5 at 12:44

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',

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.