In one of my projects I wanted to save configuration (coming from a plugin) to content entities. In Drupal however, configuration is saved to configuration entities (or configuration objects) and managed using the very solid configuration management tools.
If Drupal provides solid solutions for configuration, maybe the problem I was trying to solve was an XY problem? Was I trying to find the answer to the wrong question? Even the documentation on configuration management suggested content had nothing to do with configuration:
Configuration is the collection of admin settings that determine how the site functions, as opposed to the content of the site.
However, I discovered that several contrib modules have come across the same need to save configuration to content entities and have solved this problem in different ways.
For example, the Views Reference module saves configuration for rendering a View to a serialized
string that is part of a custom Field Type. Other modules provide generic solutions that you could easily implement in your own module: the Plugin module and Commerce come up with an agnostic field type for saving plugin configuration of any type.
In this post I will try to explain how this works using an example module.