Add $config->ClassName array overlay for module config settings #329
Open
adrianbj wants to merge 2 commits into
Open
Add $config->ClassName array overlay for module config settings #329adrianbj wants to merge 2 commits into
$config->ClassName array overlay for module config settings #329adrianbj wants to merge 2 commits into
Conversation
When $wire->config->ClassName is set to an array in site/config.php, its top-level keys are now overlaid on top of the stored DB config returned from Modules::getConfig(). This generalises the per-module pattern pioneered by TracyDebugger so any configurable module can have its settings overridden (e.g. from $_ENV) without per-module code. - Shallow merge; non-array overlays are ignored - DB rows are never mutated by the overlay - Internal configData cache continues to hold raw DB data; overlay is applied at read time after cache lookup - Module instance properties pick up the overlay automatically because setModuleConfigData() already routes through getConfig()
When rendering a module's config form, fields whose names match a key in $wire->config->ClassName get a "Currently overridden by ..." note appended below the input, and a single summary InputfieldMarkup is prepended to the form listing all overridden keys. - Override values are intentionally NOT shown (they often hold secrets); only the key names are surfaced. - Inputs remain editable so admins can still update the stored DB value as a fallback for when the override is removed. - Indicator runs after the numVisible/flagsNoUserConfig calculation so the prepended markup doesn't skew that count.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR generalises a pattern several existing modules (notably TracyDebugger) already implement locally: overriding module config values from
site/config.phpvia a$config->ClassNamearray. After this change, the override works for any configurable module without per-module code.A common use case is reading secrets from
$_ENV(.env files via phpdotenv etc.) and feeding them into module config without storing them in the database or in version-controlled files:Behavior
Modules::getConfig($class, $property = '')now overlays values from$wire->config->ClassNameon top of the stored DB config before returning.getConfig('Foo')returnsarray_merge($dbData, (array) $config->Foo)getConfig('Foo', 'apiKey')returns the overlay value when present, else DB valueconfigData[$id]cache continues to store raw DB data; overlay is applied at read time after cache lookup$config->ClassName(string, object, missing) → overlay silently ignored$config->ClassName→ no-opBecause
ModulesConfigs::setModuleConfigData()already routes throughgetConfig()when no$dataargument is provided, module instance properties applied at init time automatically pick up the overlay too — no separate change needed for that path.Admin UI indicator
To avoid confusion when an override is active,
getModuleConfigInputfields()now decorates the module config form:$config->ClassNameget anotesline appended ("Currently overridden by ...") so admins know edits won't take effect at runtime.InputfieldMarkupsummary is prepended to the form listing the overridden keys.Backward compatibility
Purely additive. Modules that don't have
$config->ClassNameset behave identically. Modules that already implement their own internal overlay (TracyDebugger) continue to work —the merge is idempotent for them.
Files changed
wire/core/Modules/ModulesConfigs.php—getConfig()implementation, PHPDoc, and admin UI indicator ingetModuleConfigInputfields()wire/core/Modules/Modules.php— PHPDoc on the wrapper