Drupal 8 Module Port - Pages and Menu routing

This is Part 2 of a blog series about my recent experiences of porting the Instagram Block module from Drupal 7 to Drupal 8. Since Drupal 8 is still in alpha, APIs are subject to change. Also I may not be using best practises so commenting is heavily appreciated!

In Drupal 7 we used to just implement hook_menu() and this would take care of everything to do with the menu items defined by our module, however in Drupal 8 we only need to register the menu item using hook_menu(). That is, we only need to define the menu item title, description, callback type and/or callback context. The rest is is handled by the new Symfony based Menu Routing system.

Show me code!

In practice this means, our hook_menu changes to look like this:

and we also add a *.routing.yaml file:

Important Notes

Make sure you define 'router_name' so that the router knows which menu item to extend.

Eventually the router will be able to handle all of the hook_menu() functionality and we will not have to write a seperate hook for menu items, but that is not yet the case.