Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem
Currently, you can set variable overrides by using the $conf array, which is setup in settings.php. This has not yet been implemented in the configuration system.
Goal
Implement this functionality.
Proposed resolution
When a DrupalConfig object is constructed, it reads the current configuration from the active store and loads it into a $data array in the object. At this time, $conf should be checked to see if it contains any overrides of this data. If so, the overrides should be merged into the $data array. Once this is done, any subsequent calls to $config->get() for those keys will return the overridden data.
Notes
- I had originally envisioned a system in which the data from $conf gets merged into the active store at reload, and if you changed $conf you would need to do another reload. This has the advantage of the active store always being canonical. However this won't work, as a lot of systems like Domain Access dynamically set these values at runtime. So we need a runtime solution as well.
- We will have to change the format of $conf a little to accomodate our new dual-key system (filename and key). I figure it will be like this:
$conf['system.performance']['cache'] = 0;
Comment | File | Size | Author |
---|---|---|---|
#26 | 1484690-26.patch | 3.43 KB | jhedstrom |
#17 | 1484690-17.patch | 3.39 KB | jhedstrom |
#12 | 1484690-12-conf.patch | 3.37 KB | Pol |
#9 | 1484690-9-conf.patch | 3.4 KB | Pol |
#8 | 1484690-8-conf.patch | 3.52 KB | Pol |
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedok, first cut patch attached.
Comment #2
PolHello,
I've just tested your patch and it works.
I've tested with :
Comment #3
Anonymous (not verified) CreditAttribution: Anonymous commentedthanks for testing the patch. we probably need some more review before we can set to RTBC.
Comment #4
jhedstromI tested #1 and it properly picked up
$conf['site_name']
. Do any of the existing$conf
settings in default.settings.php need to be updated as part of this patch?Comment #5
Anonymous (not verified) CreditAttribution: Anonymous commentedre #4 - we'll need to change anything that has been ported to the config system already, which is not much.
each follow up patch that ports some part of drupal to the config system and has a default.settings.php snippet will need to update it.
Comment #6
PolI think I can take care of this, but I need more explanations.
We have to replace all
variable_get()
with :How to do for
$conf['site_name']
?Should we replace it with system.site_name and do:
And replace
$conf['site_name']
with$conf['system']['site_name']
?Thanks.
Comment #7
Anonymous (not verified) CreditAttribution: Anonymous commentedwe only need to update $conf settings in default.settings.php that have been converted to the new config system.
as more parts are ported, the patches will need to include snippets for default.settings.php.
the main thing this patch needs now is a test.
Comment #8
PolPatch updated with tests.
Comment #9
PolUpdated patch, combined the two tests into one.
Comment #10
jhedstromIs this needed anymore? The default profile is now the testing profile.
Comment #11
Anonymous (not verified) CreditAttribution: Anonymous commentedthe patch at #9 looks ready to go to me, once we remove the $profile line as per #10.
nice work Pol!
Comment #12
PolHere we are.
Comment #13
Anonymous (not verified) CreditAttribution: Anonymous commentedok, 12 looks good, will RTBC it if the bot comes back green.
Comment #14
agentrickardIs anyone else troubled by statements like this one?
If not, I'll let it go, but it's a ternary operation inside a function call. Ugly, IMO.
Comment #15
Anonymous (not verified) CreditAttribution: Anonymous commentedre #14 - i don't feel strongly about it, so i'm ok with changing it if it bothers others.
Comment #16
agentrickardIt's just the second patch I've reviewed today that looks to me like a violation of coding standards.
Comment #17
jhedstromI re-rolled #12 to split the ternary operation into a separate line.
Comment #18
agentrickardAppeasement!
Comment #19
chx CreditAttribution: chx commentedThe proper status is "needs discussion". When we discussed this last year in Denver our thought was a local XML file. Writing settings.php is really tricky and I would love to avoid that. Really. Also, a global? In an OOP system?
Comment #20
jhedstromDo we really want to force people to write out local configuration to an XML file? My understanding was that the XML component of CMI was to be mostly hidden to non-developers.
Comment #21
Anonymous (not verified) CreditAttribution: Anonymous commentedre #19: we're not providing a mechanism via CMI to write to settings.php - that would be hard to do safely.
what we're providing is the ability (which exists now) to override configuration that lives in persistent storage with values in settings.php.
it's really ugly, because we're just using the existing ugly, global $conf. i've created #1493468: create a bootstrap config object that the config system can depend on - which will hopefully see us get rid of global $conf and replace it with something more inline with the rest of the config system.
Comment #22
agentrickardMy understanding cd this patch is that it is a shim to prevent losing existing functionality. I would expect it will be changednas D8 matures. But without this patch, we break techniques that have worked since drupal 5.
Comment #23
PolI don't know if it's appropriate, but... maybe we should do a function who loads xml 'on the fly' and use it as configuration.
Comment #24
Anonymous (not verified) CreditAttribution: Anonymous commentedre. #23 - i think that's a separate issue.
personally, i'm not sure i like the feature, but either way, please create another issue if you want to get it in - i think it's out of scope here.
Comment #25
Dave ReidIt would be nice if we could skip the call to drupal_array_merge_deep() if $data is an empty array.
Needs to also be declared as public in the interface?
Otherwise this is looking good to ensure we're not losing support for an existing feature keeping in mind we eventually want to get rid of it, but this is beneficial to implement for now.
Comment #26
jhedstromRe: #25
This patch only calls
drupal_array_merge_deep()
if it needs to, and declaresgetName()
as public.Comment #27
marcingy CreditAttribution: marcingy commentedMight be a bit cleaner using
Comment #28
Dave ReidYeah that's what I thought as well.
Comment #29
agentrickardWhen did the coding standards change to privilege ternary expressions?!?!?!
Comment #30
gddTernaries are really a matter of taste, both are valid via coding standards. I actually am not a fan of ternaries so I'm going to give this the green light.
Comment #31
Dave Reid+1 on the RTBC. It works.
Comment #32
Dries CreditAttribution: Dries commentedCommitted to 8.x. Thanks!
Comment #33
chx CreditAttribution: chx commentedIt's OK.
Comment #34
chx CreditAttribution: chx commentedOpsie crosspost :D
Comment #35.0
(not verified) CreditAttribution: commentedAdding some notes