Problem/Motivation
In IRC today, some people were surprised to learn that editing the default config shipped with themes and modules does not change anything unless you reinstall.
Proposed resolution
Create an install
subdirectory within each extension's config directory, and move default configuration to be installed in there. E.g.:
-- mymodule
---- config
------ schema
-------- mymodule.views.schema.yml
------ install
--------- views.view.myview.yml
Remaining tasks
- Patch needs review.
- Draft change record needs review: https://drupal.org/node/2234799
- The following change records will need minor updates correcting the directory path:
https://drupal.org/node/2187853
https://drupal.org/node/2020549
https://drupal.org/node/2012166
https://drupal.org/node/2012144
https://drupal.org/node/1820974
https://drupal.org/node/1876852
https://drupal.org/node/1901332
https://drupal.org/node/1907430
https://drupal.org/node/1813914 - The following handbook docs will need to be updated:
https://drupal.org/node/2120571
https://drupal.org/node/1905070
https://drupal.org/node/1667896 - File an issue to update DrupalModuleUpgrader.
- Patch should be rerolled immediately before commit, to ensure all default config is moved properly. To reroll:
- Apply the latest
-do-not-test.patch
. - Run the following script from the Drupal root:
#!/bin/bash CONFIG_DIRS="$( find core -type d -name 'config' )" for d in $CONFIG_DIRS do mkdir "$d"/install FILES="$( find $d -maxdepth 1 -name "*.yml" -exec basename {} \; )" for f in $FILES do git mv "$d"/"$f" "$d"/install/"$f" done done
- Apply https://drupal.org/files/issues/interdiff-25-29.patch to move the config module's stuff back where it belongs. ;)
- Apply the latest
User interface changes
N/A
API changes
Class constants added to Drupal\Core\Config\InstallStorage
:
CONFIG_INSTALL_DIRECTORY
CONFIG_SCHEMA_DIRECTORY
Comment | File | Size | Author |
---|---|---|---|
#71 | 2233787.71.patch | 99.71 KB | alexpott |
#71 | 66-71-interdiff.txt | 5.23 KB | alexpott |
#66 | 2233787.66.patch | 105.1 KB | alexpott |
#66 | 64-66-interdiff.txt | 729 bytes | alexpott |
#64 | 2233787.64.patch | 105.09 KB | alexpott |
Comments
Comment #1
webchickSeems like a good idea to me. I did know this is how it works, but with any other file in a module/theme it's "hack hack hack, clear the cache, see what broke" (except for very specific things like hook_install()/hook_uninstall() which are pretty clear) so I can see why people would be confused by this.
Comment #2
sunHm. I don't really like the verbosity of the directory name, but if it need be, I guess I could live with it.
The only concern + request I have is that it should be properly namespaced; i.e.:
Not
./default_config
, but./config_default
, please.In addition, I'm not sure whether "default" is really any more clear to newcomers, compared to now. To be really clear, I think it would have to be named
./config_install
Comment #3
xjmWorth discussing as a beta target, I think.
Comment #4
RainbowArrayconfig_install makes sense to me.
Comment #5
xjmconfig_install
seems okay to me too. It makes it very clear what its purpose is.Comment #6
saltednutI would rather see this remain as
config
but introduce a mechanism to reset configuration from this directory. Similar to how we have a Features revert (in D7), it would be intuitive to be able to revert to this configuration via a button click or drush command.Comment #7
sunComment #8
xjmWell, #6 would be a new feature, whereas this is a simple change. So at this point in the release cycle, that should be in contrib IMO.
Comment #9
saltednutI still am not sure if changing the directory name will help - fair to say the 'revert' functionality is not on target for 8.0.0 though.
Comment #10
alexpottI'm ++ to this if we clear evidence that this will lead to greater understanding
Comment #11
xjmWe could even stick READMEs in all the core modules' directories to explain their purpose. That might help too, but not sure if it's overkill.
Comment #12
xjmThe misconception that you can edit a module's config dir and see changes has come up many times when new developers start trying CMI, so I think that's evidence that there is an issue with understanding the directory's purpose. The question is whether changing the name helps. I think
config_install
is pretty unambiguous.Comment #13
xjmMmm. I forgot about the schemata. Maybe they could live in a separate directory?
Comment #14
xjmComment #15
dawehnerI do agree that
config_install
really describes the behaviour much better asconfig
as still better thanconfig_default
.Comment #16
xjmMaybe :
Comment #17
sunAs @brantwynn mentioned, I'm also not sure whether changing the name really improves the DX situation in substantial ways:
The directory name might be more clear, but extension authors are still trying to do something that they naturally expect to work (in some way).
Obviously, changing the config directory names/structure would be a far-reaching API change affecting all core/contrib D8 code that exists today. Compared to that, introducing a "Revert to default config" facility appears to be an API addition that is internal to the configuration system, and which would seemingly resolve the actual DX problem/use-case. (?)
Comment #18
alexpottReverting to default configuration is now much more tricky now we've removed UUIDs from default configuration entities. Managing how that expectation is delivered is going to be a similar challenge.
An possible advantage for the structure outlined in #16 by @xjm is that I think it will look even better when language overrides are in the mix.
Maybe :
Comment #19
saltednutThe outline described in #16 makes a lot of sense to me. It should alleviate some DX woes (
config/install
says, to me, "this is where my config that gets loaded on install should go"). It will also generally help people to keep their module's config directories more organized. With the additional benefit for language overrides mentioned in #18, this begins to look like a very useful solution.Comment #20
webchickNice suggestions. Changing title.
Comment #21
xjmRolling a start at a patch.
Comment #22
xjmLet's see what happens!
Shell script to move the things:
Comment #24
xjmWhat happens is that Drupal doesn't install, so let's fix that before we take a bot...
core/modules/entity/config/install/ not found
.Comment #25
xjmComment #26
xjmSo for some reason the patch in #25 prevents almost all the Configuration test group from being listed. It goes from:
To:
Haven't sorted why yet, but it's all the tests that belong to
config
rather than system that don't get run. I checked and the script doesn't move the tests somewhere strange or anything... haven't managed to debug it yet.Here's the functional changes only, for review and reroll convenience. The script in #22 can be run from the root of the Drupal installation to move all default config to the new paths.
Comment #28
xjmLOL. Okay, the script #22 moves the config module's .info.yml and routing files into an
install
dir.Comment #29
xjmThis should get us to the point that all those nice tests are found and start failing. ;)
Comment #32
xjmComment #33
xjmComment #34
xjmComment #35
xjmRetitling, since the /schema subdirectory already exists.
Draft change record: https://drupal.org/node/2234799
Comment #36
xjmAlright, looks like this is ready for review. :) Here's just the non-renames again.
Comment #37
tim.plunkettOut of curiosity, when does /config exist without /config/install?
Shame this isn't public, then we could use this in those other places and wouldn't need to hunt them down next time.
Comment #38
xjmSee
core/modules/entity/config
. Anything that provides schemata (or eventually, language overrides) but no default config of its own.Yeah, I started adding a couple public methods at first, but decided it'd be out of scope and wasn't really sure what.would be clean anyway.
Comment #39
RainbowArrayThis makes the issue title pretty long, but the original discussion about this was related to themes, so just want to make sure this issue is tackling theme config too.
Comment #41
xjmYes, it is. Profiles too.
Comment #42
xjmComment #43
xjmComment #44
xjmComment #45
xjmFound a couple more things that will silently pass even though they're looking in the wrong directory. Definitely another reason to consider making this API rather than string concatenation all over the place. Thoughts? What's the best way to do that?
The tests should also be reworked to fail if the module installs default config that the test didn't find, so we can catch things like this in the future.
Comment #46
xjm@alexpott is going to take a look at this next.
Comment #47
xjmForgot to tag in #45.
Comment #48
xjm#2184387: Remove SchemaStorage could make this less ugly and pave the way for happy public API.
Comment #49
alexpottRerolled due to #2184387: Remove SchemaStorage landing.
Due to conflict the only interdiff's possible are a bit misleading.
Comment #50
alexpottHow about we just some class constants so that there is only one place where this is hardcoded - well there is config/schema in core.services.yml but I don't see how that can be avoided.
Now we're using the same class constant everywhere
assertModuleConfig
would fail if default configuration provided by the module did not exist.Comment #51
sunI don't think there is a point in having a CONFIG_ prefix for a constant on a class that is part of the Config component... Can we rename those? E.g.:
DIRECTORY_INSTALL
DIRECTORY_SCHEMA
And, perhaps a generally understood abbreviation might even be acceptable in this case?
DIR_INSTALL
DIR_SCHEMA
Comment #52
xjmI was thinking about constants too; I think that's perfect.
We already have
CONFIG_ACTIVE_DIRECTORY
andCONFIG_STAGING_DIRECTORY
, so it makes sense to be consistent with that.DIRECTORY_INSTALL
doesn't make any sense; adjectives come before nouns in English so that would make INSTALL the noun.Comment #53
xjmProbably should be "containing configuration
schemataschemas."But how can we confirm that we haven't missed any other places where we were hardcoding the directory? Is there any way we can expose the test coverage? Or, in particular, nothing failed when I missed changing
UpdateModuleHandler
, so I wonder if that has any config at all.Other than that, I'm really liking the look of this.
Comment #54
xjmShouldn't we use the constants in here too?
Comment #55
sunThe "consistency" is actually one of the problematic parts; the
CONFIG_*_DIRECTORY
constants (1) do not contain actual pathnames, they are identifiers for two types of config directories that are expected to exist (whereas there can be additional, custom config directories), and (2) the resolved directories are full relative/absolute pathnames, whereas the constants introduced here are subpathnames/subdirectories. In short, they're not the same at all and thus consistency would only lead to confusion.On the second "linguistic" issue, PHP constants are almost always (1) namespaced with a grouping prefix (to disambiguate from other possibly existing constants) and (2) have the identifier/subject last. For example, PDO, or just simply HEAD.
For class constants, it does not make sense to include the component name in constants, as that would only result in needless repetition (like
PDO::PDO_FETCH_ASSOC
orTitle::TITLE_CHECK_PLAIN
).Note that #2190723: Add a KeyValueStore\FileStorage to replace e.g. ConfigStorage introduces a
Config\FileStorageFactory::getExtension()
method which yields the default config directory of a given extension (complementinggetActive()
+getStaging()
on the factory).— However, that cannot be used here (yet), because that patch also changes the architectural design of
InstallStorage
itself (essentially turning it into a clustered key/value store that operates on multiple storage bins instead of just one).Comment #56
xjmThe class is not Config, but various subclasses of FileStorage. And DIRECTORY_INSTALL is not comprehensible. The names in the patch are fine.
Comment #57
dawehnerIt would be great to make that static:: just in case someone really overrides it.
Comment #58
alexpott@dawehner so that leads to
Fatal error: "static::" is not allowed in compile-time constants
Rerolled due to stark.settings.yml and seven.settings.yml have been deleted.
Comment #59
dawehnerGreat work!
Comment #61
xjmRerolling.
Comment #62
alexpottRerolled ... new tour in locale and menu module became menu_ui module.
Removed needs tests since config installation and module installation is extensively tested - plus now the ConfigInstaller::installDefaultConfig() also makes use of the class constants.
Comment #64
alexpottFixed the tests... there was a new theme settings test and I did not fix the new locale tour :(
Comment #65
dawehnerI guess we should not talk about modules directly here.
Beside from that +1
Comment #66
alexpottFixed
Comment #67
dawehnerFixed
Comment #68
alexpottComment #69
alexpottComment #70
tim.plunkettBad merge :(
Comment #71
alexpottGood spot!
Comment #72
tim.plunkettThanks! I was wondering why the patch size jumped, that explained it.
Comment #73
alexpottThis patch is ripe for reroll problems
Comment #75
xjmComment #76
xjmI've updated all the listed change records and the handbook pages.