Table of Contents
The configuration API provides a central place for modules to store configuration data. This can be simple configuration like your site name, or more complex information managed with configuration entities, such as views and content types.
In Drupal 8, there are several types of information:
- Content
- Information meant to be displayed on your site: article, basic page, images, files, etc.
- Session
- Information about individual users' interactions with the site, such as whether they are logged in. This is really "state" information, but it is not stored the same way so it’s a separate type here.
- State
- Information of a temporary nature about the current state of your site. Examples: the time when Cron was last run, whether node access permissions need rebuilding, etc. See Chapter 3, State API for details of how to store this information.
- Configuration
- Information about your site that is not content and is meant to be more permanent, such as the name of your site, the content types and views you have defined, etc.
It is not always clear how to decide whether a piece of information that your module will store should be classified as content, state, or configuration. Here are some guidelines:
- Configuration vs. State
- If your information would need to be deployed from your development server to your live server, it is probably configuration and not state information.
- Configuration vs. Content
- Think site builder vs. site editor. If a "site editor" role on the site would want to edit the information, it is probably content. If only a "site builder" role would want to have the power to edit the information, then it is probably configuration. But this is not an absolute rule.
- Configuration vs. Content
- Think about numbers. If you have a huge number of items, probably it is content. If you will only ever have a few, probably it is configuration.
- Configuration vs. Content
- Configuration tends to define "types of things", such as content types, taxonomy vocabularies, etc. Then each "thing" within the type is a piece of content: a content node, a taxonomy term, etc.
There are two overall types of configuration information. Simple configuration is used for single, global settings, such as the name of your site. Configuration entities are used for pieces of information that have multiple copies; for example, views, content types, etc.