Problem/Motivation
The module ships default configuration (config/install/user_update_notify.settings.yml) but has no config schema. This causes two problems:
- Kernel and Functional tests check all installed config against its schema by default (
$strictConfigSchema = TRUE). Any test that installs the module fails with aSchemaIncompleteException("No schema for user_update_notify.settings"). Contrib or custom projects that enable this module in their own tests hit the same failure. - Without a schema, config values are not cast to the right types, cannot be translated (e.g. the email subject and body), and are not validated.
Also, enable is stored as an integer (0) in the default config, and the settings form saves the raw checkbox value instead of a boolean.
Steps to reproduce
- Create a minimal Kernel test that has
protected static $modules = ['user', 'system', 'token', 'user_update_notify'];and calls$this->installConfig(['user_update_notify']);. - Run the test.
- The test fails with
Drupal\Core\Config\Schema\SchemaIncompleteException: No schema for user_update_notify.settings.
Alternatively, install Config Inspector and look at user_update_notify.settings: it is reported as having no schema.
Proposed resolution
- Add
config/schema/user_update_notify.schema.ymldescribinguser_update_notify.settings:enable:booleanadmin_email_recipient,recipient_role,targeting_type:stringrecipient_email:emailemail_subject:label(translatable)email_body:text(translatable)target_roles,selected_fields:sequenceofstring
- Change
enable: 0toenable: falsein the default config. - Cast the checkbox value to
(bool)when savingenableinSettingsForm::submitForm().
Remaining tasks
- Review the MR.
- Decide whether an update hook should convert
enableon existing sites now. Otherwise the value is cast to a boolean the next time the settings form is saved. - Add test coverage (follow-up). With the schema in place, Kernel/Functional tests that install the module become possible.
User interface changes
None.
API changes
None.
Data model changes
A config schema is added for user_update_notify.settings. enable is now stored as a boolean instead of an integer. The keys and structure of the config are unchanged.
Issue fork user_update_notify-3631663
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
beltofteComment #6
beltofte