Problem/Motivation
Consider the block configuration schema:
block.block.*:
type: config_entity
label: 'Block'
mapping:
#...
settings:
type: block.settings.[%parent.plugin]
And now look at this configuration:
#...
id: bartik_footer
plugin: 'system_menu_block:footer'
settings:
visibility: { }
#...
Looking at the plugin value in block.block.bartik_footer we have a problem. The plugin value is the derivative ID - system_menu_block:footer
which means we end up looking for schema types of block.settings.system_menu_block:footer
whereas we intend to look for block.settings.system_menu_block
. This means we can't add a schema for the new settings being introduced by #474004: Add options to system menu block so primary and secondary menus can be blocks rather than variables.
Proposed resolution
Use colons in Drupal\Core\Config\TypedConfigManager::getFallbackName() to check for more schema fallback types.
For example:
block.block.*:
type: config_entity
label: 'Block'
mapping:
#...
settings:
type: block.settings.[%parent.plugin]
block.settings.system_menu_block:*:
type: mapping
mapping:
#... the rest of the definition.
Remaining tasks
Commit.
User interface changes
None
API changes
None
Comment | File | Size | Author |
---|---|---|---|
#31 | 28-30-interdiff.txt | 2.95 KB | alexpott |
#31 | 2317865.30.patch | 7.97 KB | alexpott |
#29 | 2317865.29.patch | 7.62 KB | alexpott |
#29 | 26-29-interdiff.txt | 4.07 KB | alexpott |
#26 | 2317865.26.patch | 7.47 KB | alexpott |
Comments
Comment #1
alexpottLike so.
Comment #2
Gábor HojtsyWoah, omg. The way we resolved it earlier is we introduced a key with the value we needed in the schema in the name of not complicating the schema format further. It was supposed to be an easy to grok and simple format.
Comment #3
vijaycs85agreed, but we didn't manage to get ride of "budle:type" format in config schema and may be we need something like like 'type_regex' to solve it?
Comment #4
Wim LeersI think (and HOPE :P) the patch in #1 contains another patch? :)
Comment #5
alexpottit does... lol...
Comment #6
Gábor HojtsyWell, I think the dynamic typing is pretty confusing already, would love not to make it even more confusing :/
Comment #7
alexpottTagging...
Comment #8
Gábor HojtsyComment #9
jibranThe fix worked see #474004-113: Add options to system menu block so primary and secondary menus can be blocks rather than variables
Comment #10
alexpott@effulgentsia wondered if we could make the plugin have a custom schema and store the regex on there. For example:
Unfortunately this can not work because if we were replacing the type using the current data (
[plugin]
vs[%parent.plugin]
) then at that point we have no idea what the type the plugin key is - that's what we're determining!The benefit of this approach is that this is easier to share.
Comment #11
xjmThis is probably beta-blocking (per discussion with @effulgentsia and @alexpott). We might settle on a solution that isn't but we're not there yet.
Comment #12
alexpottTalked about this with @effulgentsia. Using the schema system we add the schema_type_resolver to a type and then determine the type.
Schema
Data
Configuration name: config_schema_test.plugin_types
If the type is determined by the current data eg.
test.plugin_types.[plugin_id]
then we need to know a base type so that we can determine the schema type of the value being used to replace the plugin id.Comment #14
RainbowArrayI don't think this will fix the installation issue, but in reviewing this to try to find the cause of the failure I found a typo in the spelling of the word definition in several variable names. Small fix with a correction for that.
Comment #15
RainbowArrayComment #17
fagoWondering whether that is not possible to do with type-inheritance as usual? I've never really written config schema, so it might be nonsense, but I'd have thought of defining something like:
So the derivative plugin would have to add that as well. Any reasons that does not work?
Comment #18
dawehnerI am glad that this finally got a beta blocker, as this block proper schema support for views since ever.
The problem with that approach is that it doesn't support the usecase that you might have a overridden plugin class for a specific derivative instance. For example the CommentRow plugin extends the EntityRow one with additional settings. We need to be sure that the specific one is loaded as well. The idea in #17 would solve that if I understand it correctly.
Comment #19
Gábor HojtsySo TypedConfigManager::getFallbackName() resolves stars only following dots. In this case, the variable part of the element is after a colon not a dot. I would also prefer a simpler solution for this. The regex is totally black magic, the whole dynamic typing situation is already complex to understand. What about making stars work in general, not just after dots? That sounds like would be way simpler than regexing...
Comment #20
alexpottOk so here is something that will use colons in the fallback mechanism. Making stars work in general is going to add heaps of complexity to
getFallbackName()
Comment #21
effulgentsia CreditAttribution: effulgentsia commentedRetitling for clarity. I like the approach in #20, but given all the reviewers who commented in the earlier comments on prior approaches, let's get a couple more +1s on this before RTBC'ing it.
Comment #22
vijaycs85+1 for #20 as we have same pattern (.*) support already.
Comment #23
alexpottI really was not happy with the quotes in the schema type keys so that we could have a : in there. Realised that there is a better way which slightly limits the number of fallback possibilities (not sure that this is a bad thing) for an improved DX.
How much nicer is that?
Comment #24
neclimdulI guess this means this supports derivatives but not derivatives with different separators. I'm ok with that, since its pretty hard to implement and I don't really see that being used.
Comment #25
Gábor HojtsyYay, this implementation looks much better than that complicated regex stuff. I only have relatively minor comments but important for making this easy to understand. Otherwise looks good.
English should be unified on these. "check will for" definitely does not work. :D The first uses "check for definitions" which should probably also be "will check for"?
The comment and method name do not match the current implementation anymore.
Will need an issue summary update and a change notice. I'll do a draft change notice now. Needs work for the code changes needed.
Comment #26
alexpottRe: #24 yeah I thought about this too - not sure what to do. Do you think it is worth not allowing derivatives with different separators?
Re: #25
Fixed issue summary too.
Comment #27
alexpottComment #28
effulgentsia CreditAttribution: effulgentsia commentedRe #23: I'm not happy with removing the colon from the schema key wildcard pattern. For example, I wouldn't want
image.effect.image_scale*
being a fallback forimage.effect.image_scale_and_crop
. However, turns out that the YAML spec does allow colons to appear in unquoted keys, so long as they're not followed by whitespace, and Symfony's YAML parser respects that spec. Sotest.plugin_types.boolean:*:
works as a line of YAML.Re #24: Let's not hold this issue up on it, but I opened #2319503: Should TypedConfigManager::getFallbackName() support plugin derivatives whose IDs are not delimited with a colon? so we can discuss it further.
Comment #29
alexpottSure... here's a patch to swap it back and test that.
Comment #31
alexpottFixed the one star matching.
Comment #32
Gábor HojtsyFix minor syntax glitch in issue summary. Added change notice at https://www.drupal.org/node/2319739
The updated patch looks good to me :) I'm *really* glad we did not (need to) go with the regex solution.
Comment #33
Dries CreditAttribution: Dries commentedGlad we sorted this one out after all. Committed to 8.0.x. Thank you!
Comment #35
Gábor HojtsySuperb, thanks!
Comment #36
chx CreditAttribution: chx commentedThe regular expression here could be seriously simplified because you do not need to escape anything in a PCRE character class except the closing square bracket.
Comment #37
vijaycs85If anyone wonder about the above statement, please refer: http://www.yaml.org/spec/1.2/spec.html#id2788859 and raised an issue with phpStorm(http://youtrack.jetbrains.com/issue/WI-24607) as it doesn't support this atm.