Problem/Motivation
When a site builder wants to disable CSS aggregation, they might enter preprocess: 'false' in the css section of system.performance.yml. On import, Drupal stores TRUE, leaving aggregation enabled.
The default boolean config schema type uses BooleanData::getCastedValue(), which applies PHP's (bool) cast. Every string except '' and '0' becomes TRUE, whether it came from YAML or the Configuration API. While the original string 'false' would fail schema validation, casting it first produces a valid boolean with the opposite meaning.
Implications
- A project sets
css.preprocessto'false'in its sync directory to disable CSS aggregation. Importing it leaves aggregation enabled, and the next comparison still listssystem.performanceas changed. If the admin then exports the active configuration, the export writespreprocess: trueto the file. Deploying that export enables aggregation on the target site as well. - A site builder imports a custom menu with
locked: 'false'. Drupal storeslockedasTRUE. When an admin later tries to delete the menu through the UI,MenuAccessControlHandler::checkAccess()denies deletion. - Suppose a module ships
send_notifications: 'false'for a boolean setting in itsconfig/installdefaults. Installing the module enables notifications. If a later update corrects the default, it cannot tell from active configuration alone which sites deliberately enabled notifications and which inherited the miscast value.
Context: Use of 0 and 1 in Drupal and Drush
- Drush:
- Particularly in Drush, devs have long used
0and1to turn settings off and on, as illustrated in #2904502: Settings config cannot be set using drush command. A user reported on Drupal Answers thatdrush config-set advagg.settings enabled falsestoredtrue, while0storedfalse. It's only since the November 2026 fix thatconfig:setparsestrueandfalseas booleans while still passing the digits as strings by default. - Form API checkboxes:
- For an unchecked checkbox, including the one in the "Performance" form,
Checkbox::valueCallback()returns integer0. For a checked checkbox, it returns the configured#return_value, which defaults to integer1. - Boolean field defaults:
- In config schema, Core assigns the type
integerto thevalueproperty of a boolean field default. For example, the Umami demo profile setsvalue: 1as the default for thepromotefield on articles and recipes. - Schema validation:
- For boolean settings, Core's
PrimitiveTypeConstraintalready accepts0,1,'0'and'1'.
Steps to reproduce
- Start with "Aggregate CSS files" enabled at
/admin/config/development/performanceand export the configuration. - To disable aggregation, enter
preprocess: 'false'insystem.performance.yml'scsssection and import the configuration. - Return to the "Performance" page. "Aggregate CSS files" is still checked. The import should disable aggregation and report a deprecation for the quoted value.
Proposed resolution
Deprecate non-boolean input that reaches the cast for the default boolean config schema type, with four exceptions for now.
During the deprecation period, correct the cast so that 'false' disables the setting. The deprecation tells the caller to correct the input as well. If the sync file still contains the string, the next comparison will still report a change.
- Accept native booleans and the exact values
0,1,'0'and'1'without a deprecation. Existing Drush commands and scripts use the string forms, and standard checkboxes return the integers. - For other strings recognized by
FILTER_VALIDATE_BOOL, trigger a deprecation and use the parsed value. This maps'false','off','no'and an empty string toFALSE, and'true','on'and'yes'toTRUE, case-insensitively. - For any remaining input that reaches the cast, trigger a deprecation and retain the existing
(bool)cast.
Implementation
- Use an internal
ConfigBooleansubclass ofBooleanDatafor thebooleanconfig schema type. - Have
ConfigBoolean::getCastedValue()delegate input recognition and deprecation reporting to a shared internalBooleanInputhelper. - Apply
#[JsonSchema(['type' => 'boolean'])]to the overriding method so that it retains its boolean JSON Schema type. - When saving configuration, include the configuration name and property path in the deprecation message, for example
system.performance:css.preprocess. - Use
FILTER_NULL_ON_FAILUREso thatBooleanInput::parse()returnsNULLfor unrecognized input.ConfigBoolean::getCastedValue()then callsparent::getCastedValue(). A follow-up can reuseBooleanInput::parse()for thetranslatableschema flag while preserving each reader's fallback. - Update Core code that supplies strings for boolean configuration settings to pass native booleans. This includes field formatter defaults, node revision settings, hidden fields in Layout Builder and Views handler options.
- Preserve native booleans in
RecipeRunner::replaceInputValues()when a placeholder is the entire config action argument or array value. A placeholder embedded in text still uses string interpolation.
Tests
- Test that importing
preprocess: 'false'storesFALSEand triggers a deprecation that identifiessystem.performance:css.preprocess. - Test that
'1'and'01'both yieldTRUE, but only'01'triggers a deprecation.PrimitiveTypeConstraintValidator::validate()currently accepts both. Also test that' 0 'yieldsFALSEand triggers a deprecation because the original string is not exactly'0'.
Remaining tasks
Review.
User interface changes
None.
API changes
- Config
- The default
booleanconfig schema type now usesConfigBoolean. If an element of this type contains the string'false','off'or'no', callingConfigBoolean::getCastedValue()directly triggers a deprecation and returnsFALSEinstead ofTRUE.Passing non-boolean input other than the four numeric forms listed below is deprecated to be removed in the next major.
The integers
0and1and the strings'0'and'1'remain accepted without deprecation. - Recipe
- When a
Recipeuses a standalone placeholder for a boolean input, the config action now receivesFALSEorTRUEinstead of''or'1', respectively.
Data model changes
None.
Release notes snippet
Saving or importing 'false', 'off' or 'no' for a boolean configuration setting now stores FALSE instead of TRUE and triggers a deprecation.
Issue fork drupal-3644386
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
pancho