Problem/Motivation
TypedConfigManager uses a custom implementation of discovery instead of relying on a discovery class with potential decorators. We can rely on Drupal 8 patterns instead and remove some custom code.
Proposed resolution
- Implement a discovery class for configuration schema.
- Add an alter decorator to allow altering instead of one-off implementation we used to have.
- Clean up the cache implementation by relying on existing code in the parent.
Remaining tasks
- Resolve review points
- More review
User interface changes
No.
API changes
config_translation_config_translation_type_info_alter() is replaced by hook_config_schema_info_alter(), same semantics.
Comment | File | Size | Author |
---|---|---|---|
#29 | 5633-schema-discovery-29.patch | 12.28 KB | Gábor Hojtsy |
#26 | 5633-schema-discovery-26.patch | 14.71 KB | Jose Reyero |
#26 | 5633-interdiff-18-26.txt | 1.04 KB | Jose Reyero |
#18 | 5633-interdiff-16-18.txt | 699 bytes | Jose Reyero |
#18 | 5633-schema-discovery-18.patch | 14.26 KB | Jose Reyero |
Comments
Comment #1
YesCT CreditAttribution: YesCT commentedoops. probably not on sprint.
Comment #2
Gábor HojtsyThe current hook name is a lie, it does not alter the type info but rather it alters an actual element (and supposed to alter it based on type, but that is not really the scope of the hook now). It can alter anything on an actual element. Vs. the name of the hook suggesting it would alter type info (a list of all the types in their abstract level, not as applied to elements).
Comment #3
Jose Reyero CreditAttribution: Jose Reyero commentedWell, I'm not so sure about this one.
@Gábor, right it doesn't alter the type itself, but also it doesn't alter the element itself but the DataDefinition of the element
I think it's like Type Definition + When applied to actual data instances -> Data Definition. Only our data definitions happen to need some preprocessing by using actual data. So yes, the whole thing is confusing.
Anyway, what I think we really need is that 'hook_config_type_info_alter()' mentioned on some other issue and dismissed. Because by altering the 'type definition', that would be inherited by the corresponding 'data definition' and we'd have a lot less stuff to alter.
I'm thinking: what about adding proper discovery for TypedConfigManager and then we just add one of that alter hook decorators?
Whatever, not having that 'hook_config_type_info_alter()' is causing us all kind of weird hook implementations and issues for us (and config translation) so maybe we should retry that one in the first place ?
Comment #4
Jose Reyero CreditAttribution: Jose Reyero commentedThis patch:
- Uses proper discovery classes for TypedConfigManager so it gets still simpler.
- Adds a ConfigSchemaDiscovery, as a wrapper for ExtensionInstallStorage
- Adds a config_schema_info_alter() hook that would fix all our current issues / ugly hooks with config translation.
I know it may be more than simply renaming a hook, but is the proper / clean way to get where we want IMO.
Comment #5
Jose Reyero CreditAttribution: Jose Reyero commentedComment #6
Gábor HojtsyThis totally makes sense. Fantastic! Can we also remove the ugly one-off code from config translation type altering to demonstrate how standard this makes that?
Comment #7
Gábor HojtsyRetitled to something maybe better :) Review points on top of #6:
Not the actual path and name of the class either.
Dot at the end.
As per our practices / coding styles, arguments are still $schema_storage, while class properties are $schemaStorage style.
We don't have sections in the use list elsewhere. Let's use the alphabetic ordering like we do elsewhere.
I don't think this line adds any clarity to the code :) I would remove.
Also updated the issue summary.
Comment #8
Jose Reyero CreditAttribution: Jose Reyero commentedUpdated patch:
- Fixed @Gábor's issues in #7
- Renamed hook_config_translation_type_info_alter() to hook_config_schema_info_alter()
- Removed one-off code from config_translation, and some module handler dependency for ConfigTranslationFormBase
Still to do:
- Move hook documentation to... config module I guess (?)
- Think about completely removing config.storage.schema service and maybe ExtensionInstallStorage..
Comment #9
Jose Reyero CreditAttribution: Jose Reyero commentedAlso maybe LocaleConfigManager deserves some rewrite and simplification
Comment #10
Jose Reyero CreditAttribution: Jose Reyero commentedJust in case someone else is wondering, the answer to my last two questions:
- Think about completely removing config.storage.schema service and maybe ExtensionInstallStorage..
Possible but that would take tying the TypedConfigManager to a specific folder storage which I don't think is a good idea (not removing ExtensionInstallStorage which is used by install system)
- LocaleConfigManager deserves some rewrite and simplification
Yes, but that's a different issue. I may explore in a separate patch how it can use but not extend TypedConfigManager saving a lot of parameters passed back and forth..
Comment #11
Gábor HojtsyLooks good to me but testbot will be useful too :) IMHO since the hook is exposed by the base system, not the config module, it should be in system.api.php. I believe that is the standard place to system level stuff.
Comment #12
Gábor HojtsyBTW looks good to me except the place of the docs. :)
Comment #14
Jose Reyero CreditAttribution: Jose Reyero commentedUpdate patch:
- Moved hook documentation to system.api.php
(and reworderd according to new place which is 'system wide' more than 'config translation' specific)
- Fixed previous test failure which was a caching issue and as a result, an config text getting the wrong element for translation (textfield instead of text area)
I don't know whether it is the proper thing to do, but this fixes it (adding the tag to the service) in core.services.yml
Comment #15
BerdirAlterDecorator should not be used, use $this->alterInfo() instead.
Comment #16
Jose Reyero CreditAttribution: Jose Reyero commented@Berdir,
Thanks for reviewing.
Replaced AlterDecorator by $this->alterInfo().
Comment #18
Jose Reyero CreditAttribution: Jose Reyero commentedOf course, the constructor in the test needs to be updated too.
Comment #19
Gábor HojtsyLooks good :) Thanks for the review @berdir.
Comment #20
alexpottThere are been many attempts to add an alter hook to config schema and I've resisted every single one. Alter config data structures will make standard config very difficult to maintain and dynamic schema will be impossible to translate. If we can remove this part of the change and just proceed with the discovery changes I'd be happier.
Comment #21
Gábor HojtsyI think there are possible valid use cases, like a module introducing a telephone type and modifying existing known schemas to use this type, ie. providing more specificity without busting the whole system. I see the alter hook makes it too easy to do wrong things as well. Not having the alter still makes it possible to do this for someone but they would need to swap out the typed config manager. That is certainly more of a change for a contrib module and hard to say "Drupal core supported it". I see the reasons for your resistance and not having the alter will indeed make it easier to police projects to do the right thing. It will unfortunately make the innocent improvements also possible with the alter that much harder :/ I agree the other improvements on the issue are in themselves worth it.
Comment #22
Jose Reyero CreditAttribution: Jose Reyero commented(Cross-posted with Gabor's comment, so I may be repeating some reasons, posting anyway)
@alexpott,
Maybe, but I think the same kind of reasoning will apply to every other alter hook.
Won't altering plugin definitions make any plugin data more difficult to maintain?
Also if only for consistency with TypedData, which has an alter hook, you may need to be able to alter typed config accordingly.
Plus this replaces a pretty ugly hook, that happens to be already in core (hook_config_translation_type_info_alter) adding some DX consistency here. So I'd say this is not adding a hook, but fixing an existing one.. ;-)
Anyway, it was not the main purpose of this patch, so if you still think it's a bad idea, I'll be re-rolling the patch without the hook.
Comment #23
alexpottWell if we are going to keep this in - I'd like a much better description about what can go wrong with using this hook to alter existing schema... enhancing schema like what occurs in the usage in core is great - but altering :(
Comment #24
alexpottAlso plugins are not subject to static analysis. Config is special :)
Comment #25
Gábor HojtsyWhat if we disallow adding new items? That would make it a true alter :) Is that evil? :D
Comment #26
Jose Reyero CreditAttribution: Jose Reyero commented@Gábor,
Yes, we can forbid adding new items
:-P
Now seriously, these are the new comments for the hook, as suggested by @alexpott:
Does it look good?
Now time for style and grammar corrections, I guess :-D
Comment #27
Gábor HojtsyThe added explanation looks good to me and it satisfied @alexpott's concern that he pushed this back from RTBC.
Comment #29
Gábor HojtsyRerolled.
Comment #30
Gábor HojtsyI just rerolled this, so moving back to RTBC.
Comment #31
alexpottResistance is futile :( (I will regret this)
Committed 9b7ead2 and pushed to 8.0.x. Thanks!
Comment #33
Gábor HojtsyThanks all! We'll hopefully see all kinds of good uses of this instead of bad.