How to replace variable_set() with a State API call

Description

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.

Transcript

So we got "Fatal error: Call to undefined function Drupal\trails\variable_set. Okay. So we know that variable_set has been replaced.

So we go back to our code here. So we got variable_set right there, but instead we are going to use this state. Now I feel like I could guess what the signature is here but I'm going to go back to the change record and just copy something from the change record just to make sure.

So I'm going to go back until we get to the search page and I'm going to do a search for variable_set. Okay. And I'm going to go to this page -- we've been here before -- and we want to go to the "State API" page.

This collection will not only prepare you to work with and understand Drupal 8 under the hood, it will increase your skills and relevance as a developer. We cover Object Oriented Programming (OOP), how to use Composer, what the Symfony framework is and how to use its various components, plus lots, lots more. For developers really wanting to modernize their skill set, this is a great place to start.

Before watching this series, you will need a web environment with Drupal 8 installed. Follow the videos in the Setting Up a Web Environment With Drupal to set up a web environment. In the series, we use a couple different versions of Drupal 8 and provide instructions for installing each one so you can follow along with the series exactly. You can also use the latest version of Drupal 8, but there will be some slight differences between what you see in the videos and how you would put what you see into practice, but working through those differences can be excellent for learning.

Some of the key points we'll be covering include:

How to build basic module scaffolding in Drupal 8

How Object-Oriented Programming (OOP) works and how to apply what you learn to coding in Drupal 8

How to work with Symfony components included in Drupal 8

How to use Composer to keep track of code dependencies and leverage a huge library of PHP components

Who this collection is for

This collection is mostly for Drupal developers who want to upgrade their techniques to work with Drupal 8. Because many of these techniques are applicable to PHP coding in general, it can also be useful if you simply want to develop your PHP skills and wrap your mind around object-oriented programming.

Prerequisites

You will get the most out of this collection if you are comfortable with procedural coding in PHP. We will make references to how code works in Drupal 7, so it will be helpful if you have some Drupal coding experience in particular.

It looks like there might be an issue playing videos in this browser. We're working on better cross-brower experience, but in the meantime please try the latest Chrome or Firefox browsers. Or, you may be able to watch the video directly without progress tracking or transcript: