How do I create and use a custom hook? I posted a question here, which had one suggestion, but no answer. Does anyone have any advise on how to implement a custom hook in Drupal 8 which will allow other modules to update a table of contents which is created by a parent module? The table of contents will be an unordered list.
This section resides in a controller in the parent module:

$plugin_items = [];
// Call modules that implement the hook, and let them add items.
\Drupal::moduleHandler()-&gt;alter('flot_examples_toc', $plugin_items);
if (count($plugin_items &gt; 0)) {
  $output['plugins'] = [
    '#title' =&gt; 'Plugins',
    '#theme' =&gt; 'item_list',
    '#items' =&gt; $plugin_items,
  ];
}


And this resides in the child [module].module file.

use Drupal\Core\Url;

function mymodule_flot_examples_toc_alter(&amp;$item_list) {
  $options = [
    ':one' =&gt; Url::fromRoute('flot_spider_examples.example')-&gt;toString(),
  ];
  $item_list[] = t('&lt;a href=":one"&gt;Spider Chart&lt;/a&gt; (with spider plugin)', $options);
}


The parent creates an array and passes it to the children by reference. They can alter the array by adding elements to it. The parent then adds it to the render array.