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.
in #1697256-141: Create a UI for importing new configuration, sun pointed out that "The config_prefix does not necessarily contain one dot only."
we should fix that here.
Comment | File | Size | Author |
---|---|---|---|
#33 | configentity-1831774-33.patch | 14.8 KB | tim.plunkett |
#33 | interdiff.txt | 9.05 KB | tim.plunkett |
#31 | cmi-1831774-31.patch | 14.66 KB | tim.plunkett |
#31 | interdiff.txt | 5.99 KB | tim.plunkett |
#27 | 1831774-27.patch | 10.83 KB | damiankloip |
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedtag
Comment #2
gddTo some extent this is related to #1806178-2: Remove code duplication for hook_config_import_*() implementations of config entities which could remove the prefix concept entirely.
Comment #3
Gábor HojtsyThe code in question is this:
I don't see how "only one dot" is called out here, the explode result is taken from after the second dot, so it assumes it contains exactly TWO dots, not one. Which is *my* problem coming here, since this now fails the regions module patch from #1813910: Add region module to Drupal core (for editable responsive layouts) which operates with 'region' as the config prefix (note no dot), so resulting config files are region.body.yml, region.footer.yml, etc. The region module does not define any other config objects, so it would be overkill to name them region.region.body.yml just to satisfy this code. That seems to be the only workaround for now though, so I am wondering if we have a standard here that my patches do not follow (and where it is documented so I can point people there in the future if they wonder why the repetition in the config keys).
This blocks most dynamic layout patches and the SCOTCH patch for page layout assignment at #1787942: Allow assigning layouts to pages which uses page.front_page.yml, etc. keys.
Comment #4
sunOne refers to the prefix, not the full config object name.
Anyway, you're running exactly into the problem that has been introduced by the config import UI patch.
The code needs to be corrected to take the part after the config prefix as the entity id.
I fixed this in the other config issue about default config installation already, but since it is hindering your issue, it probably makes sense to separate out that fix here.
Comment #5
Gábor HojtsySo something functionally equivalent to this I assume? (In effect remove the first but only the first occurrence of the config prefix regardless of what it is).
Comment #7
sunmmm, nope, the code needs to retrieve the part after the config prefix (plus dot), but needs to perform an exact match (and must not match and entire suffix). The other issue/patch was:
#1776830-28: [META-1] Installation and uninstallation of configuration provided by a module that belongs to another module's API
$parts[$id_index]
holds the config entity ID.Comment #8
Gábor Hojtsy@sun: I'm not getting this. 'config_prefix' SHOULD appear at the start of the config key since, we are asking with $source_storage->listAll($entity_info['config_prefix']) right? So we are iterating through those items in $config_name. I could also do substr() or preg_replace() matching the string at the start or other tricks. The explode in the patch was supposed to remove the config name only at the start. I feel like I'm not getting something here...
Comment #9
sunk, let me explain:
1) config_prefix contains the entire prefix that is used for the dynamic config objects.
2) config_prefix can contain 1-n dots/periods. The amount of dots is not enforced anywhere and should not be enforced.
3) config_prefix only denotes a prefix; the suffix that follows can contain more than one part. (or more than one dot)
What we need to extract is the part of the config object name that immediately follows the config_prefix, whereas the config_prefix is of arbitrary length and can contain an arbitrary amount of dots, and not everything after the config_prefix still belongs to the part that is the ID.
In all of these, we need to match "ID":
Thus, that's:
Comment #10
sunMarked #1901988: Importing a ConfigEntity with a dot in the machine name fails as duplicate of this issue.
Quoting myself from there:
Comment #11
tim.plunkettWhat is the use case for multiple dots in a config prefix? Why don't we just standardize on one dot, and enforce that?
Also, what is the use case for something like
foo.bar.baz.ID.qux
, where this is information after the ID that isn't the ID?See #1901988: Importing a ConfigEntity with a dot in the machine name fails for the opposite issue.
Comment #12
tim.plunkettOkay, I cross-posted with sun marking my issue a duplicate.
sun, if you disagree with the approach of that issue, I invite you to fix the bugs exposed by this patch.
A reasonable fix remains in the other issue.
Comment #13
sun1) I'm absolutely certain that we do not want to enforce a magic standard for config entity prefixes to contain a single dot only. An entity config object like
foo.super.sub.bar
should be possible.2) I also think that a horizontal extensibility should be a possibility for config entity types to decide to be used, if applicable and useful. This essentially circles back into the discussion of how Module A can add settings for a config entity of Module B. Very concrete use-cases are:
It was the block plugins patch that suddenly introduced config entity IDs that may consist of dots — but the architectural validity of that was never formally discussed and agreed on, so let's not make the mistake and interpret that precedent as a rule. :)
Comment #14
tim.plunkettRelated: #1760358: Provide a way to extract the ID from a config object name
Comment #15
damiankloip CreditAttribution: damiankloip commentedFor starters, Can we meet in the middle and allow any length prefix by doing something like this?
Comment #16
tim.plunkettSure. Let's see how #12+#15 fairs.
Though it is
$id = substr($config_name, strlen($entity_info['config_prefix'] . '.'));
, not$id = substr($config_name, strlen($entity_info['config_prefix']));
Comment #17
damiankloip CreditAttribution: damiankloip commentedOops, yeah. That's better :) I think I was thinking of the method....
Comment #18
damiankloip CreditAttribution: damiankloip commentedAssigning to sun to review the approach taken here. I think this is good; definitely better than what we have now.
Comment #19
alexpottRerolled due to #1889854: Config import breaks on protected entity properties landing... and added comment to code to explain why
Config::clear()
can not be used duringConfigStorageController::delete()
Comment #20
gddIt seems like its worth making a wrapper function for this, even though its just one line. It would make the code more self-documenting, and it would make future changes easier to address, since it seems likely we aren't done with this topic.
Comment #21
tim.plunkettConfigStorageController already has getConfigPrefix(), so it seems like a good place to add a static method for this.
Comment #22
damiankloip CreditAttribution: damiankloip commentedWorking on this.
Comment #23
damiankloip CreditAttribution: damiankloip commentedHere is an extractID method on the ConfigStorageController. Better names for this welcome.
Comment #24
alexpottHow about idFromConfigName()... Or something like that... I think we need to say what we are extracting from.
Comment #25
damiankloip CreditAttribution: damiankloip commentedThat's a better name :) Let's go with that.
Comment #27
damiankloip CreditAttribution: damiankloip commentedSorry, forgot to change the method name in the test.
Comment #28
damiankloip CreditAttribution: damiankloip commentedAnd also forgot the comment above in the test..
Comment #29
gddI hate to bikeshed method names, but I'd like to see it start with a verb like get.
Comment #30
damiankloip CreditAttribution: damiankloip commentedFeel free to change the patch.
Comment #31
tim.plunketts/idFromConfigName/getIDFromConfigName/g
As well as some other clean-ups of the various methods in use replaced by this helper.
Comment #32
sunAlright. This issue seems to be unnecessarily blocked by my earlier considerations.
I guess it is OK to allow for dotted config entity IDs for now. We can still change our minds later.
However, if we do so, then we definitely need to clarify this somewhere. I'm not sure what the best place is, but quite potentially, the initial class' phpDoc of ConfigStorageController might be most appropriate. In there, we'd need to add a clarification along the lines of this:
Makes sense?
Speaking of, I've seen many core developers running into the pitfall that the config_prefix does not contain a trailing dot. Meanwhile, I think we should do this:
#1914742: Make config_prefix always contain a trailing dot
Aside from that, happy to move forward here. However, some remarks on the latest patch:
Huh?
Doesn't this directly imply that there is a critical bug in the config manifest architecture?
How can there be any kind of config file that goes through Config and which uses dots in config keys names...? This usage essentially presents a huge conflict with #1701014: Validate config object names
If we do not have a (major) issue for that yet, then we have to create one. It is very important that we are tracking major issues like this, as soon as we discover them, especially at this point in the release cycle.
Can we rename this to "dotted.default" ?
"config" is a bit confusing + unnecessary in a config name of a config system test.
Also noteworthy:
By changing and renaming this existing file, we're implicitly removing the explicit config system test coverage for config names without a dot.
Good unit testing practices would dictate that we need to add a separate, dotted default config file, instead of changing the existing, so that there is explicit test coverage for both possible variations.
Can we create a separate 'dotted.default' next to 'default'?
Huh? :-)
Comment #33
tim.plunkettAdded that to the docblock with a couple grammar tweaks.
So, yes, manifests incorrectly allow a key that could contain dots. Look at manifest.block.block.yml in your install, for example.
If that's wrong, then it needs a new issue to change manifests.
I renamed the file, but I did not add a second one. I don't see the benefit, and didn't see which tests were important to duplicate.
In converting all of the "list(, , $id) = explode('.', $name);" occurrences, I realized that the importTestViews() method needlessly scans for all files. In theory, the only files in test_views directory are views, but this is cleaner.
See #1915272: Move _breakpoint_delete_breakpoints() into BreakpointGroupStorageController for the follow-up so that all calls to the new getIDFromConfigName() are in storage controllers, where they belong.
Comment #34
sunThanks. I will remind you about the loss of explicit test coverage for entity IDs without dots when the first bug report is filed. ;)
#1915800: Keys in manifest files contain dots, but Config does not allow for dots in config keys
Comment #35
catchI had to look at this a couple of times but this looks fine and the shortcut diff is encouraging. Committed/pushed to 8.x.