Drupal 8 Building Blocks
Last week we looked at the Configuration API - the natural successor to the variable_set() / variable_get() API - while building a block in Drupal 8. This week we continue working on our block and associated settings by adding a menu item. In Drupal 7, creating a menu link was done in the ever-useful hook_menu(). In Drupal 8, however, hook_menu() is gone and we have a couple new conventions to replace it. Along the way, we'll also look at yet one more way to store configuration specifically for blocks.
Which files to use if you're starting this series from here - 0:34
In this video we point you in the right direction for getting your files set up if you’re just jumping in or haven’t been copying our changes in real time.
How to register a menu link and find the ID for an existing menu link - 5:03
In Drupal 7, hook_menu() took care of creating menu items for us while also defining our routes. In Drupal 8, however, the routing and menu items have been split apart. In this video we look at how to create a menu item by using a menu links YAML file, and also how to dig up the menu link ID for another menu item if we want to add our link as part of a hierarchy.
How to show a link to our module configuration form from the module listing page - 1:13
To complete our module configuration form, we need to add a link from the Extend page to the form, and that’s what we do in this video.
How to set up a block configuration form, and a benefit of using plugins - 5:27
So, we’ve built a configuration form for our module, but how do we edit the one that comes with our block plugin? In this video we walk through how to find a good example in the Drupal 8 code base and we start modifying it to suit our needs.
(FREE!) How to use block settings in a block configuration form - 3:35
After we figure out how to store block settings (which is yet one more storage system different from the Configuration API and the State API), we demonstrate how to actually use the settings in our configuration form.
Have an awesome week!
- Chris Shattuck