Closed (fixed)
Project:
Drupal core
Version:
9.1.x-dev
Component:
language system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
23 Apr 2020 at 21:12 UTC
Updated:
20 May 2020 at 08:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
stefanos.petrakisHere is the patch.
Comment #3
longwaveThanks for working on this!
I think you need to implement
ContainerFactoryPluginInterfaceto inject the killswitch service from the container when the plugin is instantiated - we don't have autowiring yet, unfortunately.While it looks awkward Drupal uses snake_case for all variables, except member variables which use camelCase, so this should be:
Comment #4
stefanos.petrakisMany thanks for double checking, here is the better version of the patch.
Comment #5
longwaveLooks great now!
Comment #6
plachLooks good to me as well, however this is now a 9.1.x issue (that might still be considered for backporting).
Comment #7
plachSpoke with @xjm about this: to be able to safely backport this to 8.9, we need to add a BC layer for the constructor param and a deprecation error stating that the param is optional in 9.0 and required in 10.0. See FileTranslation::__construct() for an example. The unit test should cover also the deprecation, so we could add the unit test class here and the actual test coverage in #3130104: Add unit test coverage for LanguageNegotiationBrowser.
Comment #8
stefanos.petrakisThanks for all the infos @plach.
I guessed first off we would need a CR for the deprecation error, here is a draft => https://www.drupal.org/node/3132773
I updated the constructor and implemented a single deprecation check test.
Back to review mode.
Comment #9
andypostIt could be done backward compatible way like #3126127-11: Fix LanguageNegotiationMethodInterface::getLangcode() result docblock
As negotiator is plugin then setter injection instead of constructor one makes the change future-proof.
Tldr kill switch will change in session related issues so better not introduce constructor argument which could be deprecated
Comment #10
plachGood point, that's probably the reason why DI wasn't used in the first place...
Comment #11
stefanos.petrakisThanks a lot @andypost for the feedback, very enlightening. Will pick this up again.
Comment #12
stefanos.petrakisThis is a different implementation than what was proposed so far, therefore:
Asking the bot.
Comment #13
andypostGreat! Btw I find this setter useless as you can access class's property directly.
CR maybe required... Because plugin now implements the new interface
Comment #14
plachThanks!
Usage of
privatevisibility is controversial and whether it should be considered ok is still being decided, so let's make thisprotectedto avoid discussions down the line.I agree with Andy: given that we can access private/protected members from a static method, the setter is not needed. It would be if this were a service exploiting setter injection via the container.
Comment #15
stefanos.petrakisOne more try here, thanks for the feedback and patience.
@plach, point 1. is definitely an invitation for more questions :) Any links to where I can read some more on this controversy? I am coming from a place in my mind where I would favor private over protected.
This kind of injection - neither a setter nor a constructor one - does it go by a specific name?
Comment #16
andypostIt looks RTBC for me
Comment #17
andypostComment #18
plachLooks good to me as well. I'm not sure we'd normally need a CR for such a change, given that plugins are not public API, but since we already have one, can we update it?
Comment #22
plachCommitted b152620 and pushed to 9.1.x and friends. Thanks!
Comment #23
plachI cannot find the issue I had in mind, asked in Slack, I will post it here once I get a reply.
Comment #24
plachComment #25
stefanos.petrakis@plach, @andypost, @longwave: Many thanks! I will update the CR accordingly and post back here a short update.
Comment #26
andypostI think related exactly about it
Comment #27
andypostMaybe CR needs better wording, like "service explicitly depends on policy"
Because it's plugin it should not be created directly - there's plugin manager
But implementation of interface should be mentioned
Comment #28
plach@stefanos.petrakis:
The oldest issue I could find discussing private visibility is #2081945: [Policy, no patch] Reintroduce 'private' visibility to object-oriented code., a related discussion then took place at #3019332: Use final to define classes that are NOT extension points.
Comment #29
plachNot that I know of. If it were me, I'd probably call it "static factory method injection" ;)
Comment #30
andypostLooks it's all a factory) https://refactoring.guru/design-patterns/factory-method
Comment #31
stefanos.petrakisJust updated the CR to reflect the committed changes and taking comments into consideration.
According to https://www.drupal.org/contributor-tasks/draft-change-record, one should now set this issue to "Needs review", but I think we are past this point. But, the CR still needs some review I guess before it's published. Suggestions?
Comment #32
andypostLooks great and could be published!
Comment #33
stefanos.petrakisComment #34
stefanos.petrakisAll right then, just published the CR.
Comment #35
andypostJust found that it missing unittest coverage #3130104: Add unit test coverage for LanguageNegotiationBrowser
This plugin does not use plugin arguments (
$configuration, $plugin_id, $plugin_definition) which are not passed to constructor now, the pointed issue should catch and solve it