September 2014

After several weeks of building our first block in Drupal 8, this week we wrap it up by troubleshooting some block configuration form issues and also take a broader look at ways we can improve what we've done so far. Enjoy!

(FREE!) How to use the Configuration API as a service - 1:48

In previous examples we were passed a configuration object we could work with, but in our block configuration form we have to figure out how to tap into the dependency injection container and get the service ourselves.

Testing out our module settings and troubleshooting a problem with saving the value - 1:32

In this video we give our module settings page a trial run and discover a bug we’ll have no problem squashing.

Troubleshooting our block configuration form - 3:35

Here we do our final tie-in to make sure our block configuration form is on speaking terms with our module configuration. Again, we run into an unexpected issue but our spirits are not daunted.

Adding a second block and ways to improve our block configuration - 1:24

Now that our block plugin is working exactly like we wanted it to, we step back and discuss what might make it even better.

Have an awesome week!

- Chris Shattuck

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

There's two major APIs bundled with Drupal 8 that allow us to store and retrieve data. Over the last several weeks you've seen one of them - the State API - in action. This week we dive into the other side, the Configuration API. In Drupal 7, in order to schlep configuration around we had to use a module called Features which was incredibly useful, but touchy and challenging to work. In Drupal 8, passing this data around multiple instances of a site is baked right in, and it's called the Configuration API.

And there was much rejoicing!

Removing unnecessary overrides and upgrading drupal_map_asscoc() - 5:25

Now that we’ve copied over an example of a form from Drupal’s core code base, we review the various methods and pull out several pieces we’re not going to need for our own configuration form.

(FREE!) How to use the Configuration API to store default module settings, replacing variable_set() - 4:18

In this video we meet the Configuration API which is used to store our module settings. The Configuration API is similar in many ways to the State API, but it has some additional pieces we need to work with.

How to update configuration with the Configuration API and submitting a module settings form - 1:23

In the previous video we looked at how to set defaults for configuration, and here we demonstrate how to save changes when a block configuration form is submitted.

How to add a page for our module configuration form - 4:44

We now have all of the pieces we need for our module configuration form, except of course a way to see it! In this video we add a route to give our form a place to live.

How to get our default configuration value to register while doing development - 1:14

Since configuration YAML files are only pulled into the database when a module is installed, we do a little reinstall dance to make the magic happen.

Steadily and surely we've been working on the process of upgrading module from Drupal 7 to Drupal 8. By the time we complete this process, we'll have touched on many of the new and improved APIs in 8. This week we look at replacing a couple other pieces that have been removed since Drupal 7, the $_GET['q'] and variable_del(), and begin to dive into forms in D8.

How to replace the $_GET['q'] and what to do when getting a "Drupal class not found" error - 3:40

If you get a funny feeling whenever you see $_GET in your code, then your OOP instincts are really starting to develop. In this video, we figure out how to replace that $_GET[‘q’] with something less global and more OOP-y.

How to replace variable_del() with a State API call - 1:03

Int his video we clear out the state variable we’ve been working with to start fresh.

How to upgrade hook_block_view() and format_interval() - 4:31

Now that we’re storing values for visited pages with the State API, the next logical step is actually displaying that info in our block. So, in this video we get build out our content and also fix a call to a long-gone format_interval() function.

Overview of the pieces we need for our module configuration form, and finding a good example - 3:21

The configuration form in Drupal 8 requires a bit more setup than Drupal 7. The upside is that the structure and format is similar to other forms that you’ll use in Drupal 8. In this video we talk through the pieces we’ll need for that form and dig up an example in the Drupal 8 code base.

(FREE!) How forms are structured in Drupal 8 - 2:07

In the same way that block code was consolidated into a single class in Drupal 8, forms also are encapsulated into a single form class. Here we look at a simple form example.

- Chris Shattuck

In Drupal 7, when you wanted to save arbitrary data to the database you would use variable_set() and variable_get(). The problem with this system was that sometimes you wanted to store this same data across multiple instances of your site - like the name of your site - and other times you wanted different values for each instance. The solution in Drupal 8 is to split the two use cases into separate APIs.

This week we look at these two APIs - the State API and Configuration APIs - as we continue the process of upgrading our Drupal 7 module.

(FREE!) A comparison of the State API and the Configuration API and how they replace variable_get() - 2:37

In Drupal 8, variable_set() and variable_get() are no more. Instead, their purpose has been replaced by two separate storage APIs. In this video we go over the role of these two APIs and when you might want to use each.

How to use the State API to store arbitrary values - 2:07

In this video we cover the specific syntax of using the State API before we dive in and start using it.

How to replace variable_get() with a State API call - 0:55

Upgrading a module is often just hitting a series of errors and fixing them. In this video we tackle our first error by replacing out a variable_get() call with some new and shiny State API code.

How to replace drupal_get_title() with a call to the "title resolver" service - 2:40

Here we figure out how to get the title of the current page. It’s not as simple as it used to be, but we break down the process into understandable pieces.

How to replace variable_set() with a State API call - 1:23

We’ve already covered how to upgrade variable_get() calls, and in this video we complete the circle by using the State API to set a value.

Have a great 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.