Background
I am creating a schema for a custom module's config settings, which are saved from a simple settings form. It has some basic fields, such as a checkbox for a Boolean value for hiding some data. However, it also has an entity reference field (e.g. hide_data_terms
) that allows selecting taxonomy terms from a specific bundle data_terms
. It will save the term IDs to the settings YAML.
Here's my attempt at a my_module.schema.yml so far:
my_module.settings:
type: mapping
label: Settings
mapping:
hide_data:
type: boolean
label: 'Hide Data'
hide_data_terms:
type: entity_reference_selection.default:taxonomy_term
label: 'Hide Data for Terms'
Problem
I'm not sure if entity_reference_selection.default:taxonomy_term
is correct. Also, I have three terms saved from the settings page, and when using Config Inspector, it shows errors like this:
Name | Label | Type | Value | Error
---------------------------------------------
hide_data_terms.0 | Undefined | undefined | 1234 | missing schema
hide_data_terms.1 | Undefined | undefined | 2034 | missing schema
hide_data_terms.2 | Undefined | undefined | 3287 | missing schema
my_module.settings.yml looks like this, with hide_data_terms
containing an array of taxonomy term IDs:
hide_data: false
hide_data_terms:
- 1234
- 2034
- 3287
What's wrong with the schema, if anything, or what should it be? I can't create a schema for each array element, because there can be any number of terms selected, or none of them.
Another Question:
The settings YAML does not have a "default config hash" for some reason. Most config YAMLs have it. Is that needed, and why isn't that in there?
Edit: I found the answer to the default config hash question. That is only used when the config is added on module install. See ConfigInstaller.php and search for default_config_hash
.