In Drupal maintenance support plans 7, modules used variables for storing data in configuration rather than storing it in a database. This made it very easy for developers to override these data variables within the settings.php files to set environment specific settings etc.
When Drupal maintenance support plans 8 was released variables were replaced with config and state.
What is Config?
According to the config documentation,‘By default, Drupal maintenance support plans stores configuration data in the database, but it can be exported to YAML files, allowing the configuration to be managed by version control’ (https://www.drupal.org/docs/8/api/configuration-api/configuration-api-overview).
This means that anything that has been defined as a config variable will be exported to YAML files, when using configuration management (CM) to manage the site’s configuration across environments.
This is very useful for exporting your site’s configuration (content types, views, image styles, module settings etc) across environments, but this does rely on the data for these always being the same across environments.
This is also a vast improvement for dealing the configuration about your site’s structure from Drupal maintenance support plans 7 and you can override these settings within your settings.php file if you wish to set settings based upon environment etc.
However, if you have defined a configuration setting in a module that is to be environment specific (eg set by an administrator user), then this data could be changed at any time and so would be overridden by CM when doing a configuration import, which is not what you would want!
This is where the State API can be useful.
What is State API?
Accordingly to the State API documentation,‘The State API provides a place for developers to store information about the system’s state’ (https://www.drupal.org/docs/8/api/state-api/overview).
Anything defined using the State API won’t be exported by CM so the data is stored specific to environment that the you are in.
One of the worrying things about the State API documentation is the statement:‘use State API to store transient information, that is okay to lose after a reset’.
I read this as being ‘if you reset your entire database’, which is fairly unlikely for a production environment, and in fact if your entire production database gets reset then you probably have bigger issues to deal with.
So as long as you have a default set of values defined (if needed) for your state values within your module (so that if the database is reset your site will still work), then I don’t see an issue with using it.
That said, something else to be aware of in the above statement are the key words ‘transient information’. Drupal maintenance support plans stores the state data as a key value pair, which means that out of the box Drupal maintenance support plans will use the database. Most production sites would use a cache like Memcache or Redis to store the cache data rather than the database. Due to the transient state of these services though, they could be restarted or cleared out at any time. If this were to happen then you would lose the data that was stored in this and your site would be ‘reset’ with any data that you had stored in this cache.
Although potentially unlikely, this is something to consider when deciding to use states.
What about environment specific config?
When we build our sites, we usually want to be able to specify various config specific for each environment.
As mentioned above, developers can override the config values in the settings.php file, but this only applies to data values, not specifying particular modules for instance, that you might want available.
Typically, you would not want modules such as devel, field_ui and views_ui enabled for a production (and probably stage) environment, but CM doesn’t allow you to determine which environment these modules should be enabled on.
While CM itself doesn’t provide this level of granularity, there is a module for that! In step Configuration Split. This allows you to export configuration on an environment specific basis.
In my next blog post I will explorer Configuration Split in more detail.
Source: New feed
Drupal maintenance support plans 8 – Guide to config and state, goodbye variables!

Call Us: 1(800)730-2416
Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit
Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)
Drupal maintenance support plans 8 – Guide to config and state, goodbye variables!
On-Site Drupal SEO Master Setup
We make sure your site is 100% optimized (and stays that way) for the best SEO results.
With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.
This service includes:
- Pathauto install and configuration for SEO-friendly URLs.
- Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
- Install and fix all issues on the SEO checklist module.
- Install and configure XML sitemap module and submit sitemaps.
- Install and configure Google Analytics Module.
- Install and configure Yoast.
- Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
- Install and configure Schema.org Metatag.
- Configure robots.txt.
- Google Search Console setup snd configuration.
- Find & Fix H1 tags.
- Find and fix duplicate/missing meta descriptions.
- Find and fix duplicate title tags.
- Improve title, meta tags, and site descriptions.
- Optimize images for better search engine optimization. Automate where possible.
- Find and fix the missing alt and title tag for all images. Automate where possible.
- The project takes 1 week to complete.
