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

Add to playlist

Add to , or

Add to new playlist:

Add to playlist
This is a member-only feature
But, it's easy to become a member

Add to cart:


Loading...
Contact us

Below are the supported keyboard shortcuts for our video player.

space
Start / stop video
shift
Go to next video
shift
Go to previous video
Increase or decrease player speed by 20%
Skip ahead or go back by 15 seconds
1...9
Jump to a percentage (2 is 20%, for example)
f
Toggle full screen
Videos Pricing More Search
BuildAModule Logo Icon BuildAModule Logo Icon
Become a member!
$29
1 month
$156
6 months
10% off
$276
12 months
20% off
All memberships come with the following:
24 / 7 access to the entire 1800+ video library
An innovative video player with a rolling transcript
Extensive Drupal and cross-platform training
A thorough and thoughtful training style
Progress tracking
Take notes on specific video sections
Intuitive multi-user management
How many users?
user
Go solo with a single user, or give multiple team members access through one account and get discounts by bundling multiple users into a single membership.