5 Videos on Saving Custom Data to a Drupal 8 Database
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.
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.
In this video we cover the specific syntax of using the State API before we dive in and start using it.
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.
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.
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