In one of my projects I found myself needing to save configuration (coming from a plugin) to content entities. In Drupal however, configuration is saved to configuration entities (or configuration objects).
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.
Like the Views Reference module that saves configuration linked to a specific View to a string
property belonging to field type made for the purpose. Other modules actually provide generic solutions that you could easily integrate in their 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 the way this works with an example module.