Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
language system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
25 Mar 2014 at 12:41 UTC
Updated:
2 Feb 2015 at 15:04 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
ianthomas_ukComment #2
ianthomas_ukThis is the work from #2166915: Remove uses of deprecated language functions in tests and procedural code. It uses \Drupal but is a good base to start from.
Comment #3
ianthomas_ukMight as well test that
Comment #4
ianthomas_ukHere are a few classes switched to dependency injection. Uploading partly for testing, but I'd also appreciate reviews of the interdiff to say if I'm doing the right thing.
Comment #6
martin107 commentedComment #7
ianthomas_ukThis is a plain reroll of #4, so will likely fail tests
Comment #9
ianthomas_ukThis should fix the most common failure
Comment #11
martin107 commentedFixed constructors to get LanguageListTest to pass.... these errors seem common to many other failings
Comment #13
ianthomas_ukbuildForm() is actually called statically (even though it's not marked static - gotta love php), so should use the \Drupal wrapper.
Comment #14
ianthomas_ukTweaked the title to capture any calls that have slipped back in after the earlier patches were committed, and here's a new patch with some more replacements (just a few left now that needed more thought).
Comment #16
ianthomas_ukFix missing use statement in Drupal\node\Plugin\Search
Comment #18
ianthomas_ukThis fixes the most common failure
Comment #20
ianthomas_ukThis should replace all the remaining calls and fixes the error in #18. If it's green it will need reviews.
Comment #22
ianthomas_ukA couple of child classes needed updating
Comment #24
ianthomas_ukA couple of tests needed updating to mock the new dependencies
Comment #25
martin107 commentedI have worked on this issue and am quite happy to work on it again... so just let me know if I can help out...
But for the moment putting my reviewers hat on and thinking.
There are several examples of procedural function calls, within classes .. the trend is to move to direct dependency injection unless in an .module of .install file etc
Here is example in the class \Drupal\Core\Session\UserSession
Where the languageManager service could be injected.
Also the config_translation.access.form service definition arguments could be updated to directly inject the languageManager into the class \Drupal\config_translation\Access\ConfigTranslationFormAccess.
Comment #26
ianthomas_ukI've tried to inject the language manager in any functions that use the create(ContainerInterface) factory pattern, although it's quite possible I've missed some, I'll have a closer look later. We should also be able to easily add parameters to service definitions.
To inject it for other classes would need interfaces, which I didn't really want to do on an issue like this - I think that would be better done in issues that replace all calls to \Drupal() in a module at the same time, with a single change to the interface. I also found some methods that are being called statically, e.g. buildForm().
Comment #27
ianthomas_ukI've had another look through and can't find any places where we could use injected objects without changing an API, so I think we should just go with the patch as it is for the purposes of this issue.
It did need a reroll however (something about a beta blocker getting committed), so here's an updated patch
Comment #29
ianthomas_ukParameter order wasn't consistent between parent and child classes in #27
Comment #31
ianthomas_ukThis should be the proper reroll of #24
Comment #33
ianthomas_uktry again. I can't generate an interdiff anymore, but the diffdiff looks sensible and the previously failing test now passes locally.
Comment #34
martin107 commentedI have taken a slow, careful scan of this patch, it looks good to me
Nothing out of scope, all changes appropriate, a good cleanup.
I have worked on this so won't move to RTBC but +1 from me.
Comment #35
ParisLiakos commentedlets store the language manager to a variable to avoid some extra \Drupal:: calls
Comment #36
penyaskitoNeeds work per #35.
Comment #37
martin107 commentedReroll before doing #35.
Lots of simple touches needed, but the sheer number of them, makes me think I will have to come back to this.
Comment #38
martin107 commentedComment #40
martin107 commentedWhile merging with recent changes the order of the final parameters to ContentEntityDatabaseStorage::_construct(), cache and languageManager
has have been reversed. So all changes are of the form
This will not fix all errors. Just ContentEntityDatabaseStorageTest.php
Comment #41
martin107 commentedComment #43
martin107 commentedRats, #40 waited 11.5 hours in the queue.... in the mean time #2285083: Rename contact category to contact form was committed and caused a reroll.
in the end no drama, a single line fix to ConfigTranslationUiTest,
Comment #45
martin107 commentedFixed a couple of side issues, just posting what I have so far..I have not fixed the failing error yet!
a) This issue introduces a new test which contains the flaw that #2322889: Various setUp() and tearDown() methods are not protected fixed.
b) The name of the content entity type is now menu_link_content :-
This seems to be the correct thing to do, but now as I run this test through the debugger by the time the program reaches this line, the contents of the relevant table in the database are empty. So my problem has become why is the db not being populated correctly?
Comment #47
martin107 commentedPatch no longer applied .. reroll.
As far as I can see all changes related to #1987882: Convert content_translation routes to a new style controller - anyway in all instances changes in head taken over changes in this patch - that was appropriate as only modern dependency injected function a calls were made in that patch.
So this patch get a little smaller.
Comment #48
martin107 commentedComment #50
martin107 commentedI am finding stepping through MenuRouterRebuildTest a bit of a pain it takes several minutes to get to the point of interest.
I want to speed up the whole process before fixing the bug by moving from extending WebTestBase to KernelTestBase.
To pull some quotes form #2287223: Use KernelTestBase for config schema tests where possible
extending KernelTestBase still makes MenuRouteRebuildTests an integration test, BUT I see a large speedup in test time.
The time taken to run MenuRouteRebuildTests from the command line drops from 28 seconds to 4 secs which should translate to an even bigger speedup when I start stepping through the debugger.
The question in the back of my mind is that I may have changed the setup of the test in some subtle way.
If reviewers could comment I would be grateful...
Comment #52
martin107 commentedLots has changed in the language module recently ... which is a good thing.
So this is a reroll... some things have become simplified.
Comment #54
martin107 commentedAh rats, In the last comment lots of tests pasts... but I did not run a lint check of all files modified :)
now I have and there should be more more errors of this type
Comment #56
martin107 commentedReverted a line in DisplayPluginBase.php, which is now an unnecessary change.
Seems to be responsible for most of the exceptions.
Comment #58
martin107 commentedHmm back to the same stage as #50.
Not sure how to proceed, I think it maybe something trivial.
Comment #59
ianthomas_uk#2328293: Remove usage of language_list() has a much more up to date patch that covers language_list() and some injection. Let's get that reviewed and committed, then come back here to do the other functions.
Comment #60
gábor hojtsy#2328293: Remove usage of language_list() is now RTBC. Let's get that in :)
Comment #61
gábor hojtsyI mean and THEN get back here to work on the rest.
Comment #62
ianthomas_uk#2328293: Remove usage of language_list() has been committed
Comment #63
jeroentNew attempt.
Function language and language_list are already removed so language_load and language_default are the only remaining.
Comment #65
jeroentComment #66
jeroentFixed the failing tests.
Comment #68
jeroentThere are still 4 failing tests in LanguageUILanguageNegotiationTest.
I will investigate this further tomorrow.
Comment #70
gábor hojtsyComment #71
jeroentComment #72
jeroentI think I was half asleep last night.
Comment #73
gábor hojtsyThe key to review I think with the patch is that all the places you took the language manager from \Drupal, none of them had a language manager injected locally?
Comment #74
ianthomas_ukThe ordering of the assignments doesn't match the ordering of the constructor parameters
This could use $this->languageManager()
This could use $this->languageManager()
Looks fine other than that - I couldn't see a way to do any more injection than we already are
Comment #75
gábor hojtsyComment #76
jeroentMade changes as suggested by ianthomas_uk in #2225427-74: Remove remaining uses of deprecated language functions (mostly in object oriented code).
Comment #77
lomo commentedFound one more call to \Drupal::languageManager() where we could use the injected service, instead. (Damn... the patch-76 should have been removed.)
Comment #78
develcuy commentedComment #79
gábor hojtsy@DevelCuy: the issue is still a perfect one to review on sprint weekend. :)
Comment #80
ianthomas_ukComments have been addressed, patch #77 looks good now
Comment #81
develcuy commentedRemoved SprintWeekend2015Queue by mistake.
Comment #82
alexpottThis issue is a prioritized change (deprecated functions) as per https://www.drupal.org/core/beta-changes and it's benefits outweigh any disruption. Committed c34c3df and pushed to 8.0.x. Thanks!
Fixed on commit.
Comment #84
gábor hojtsyFantastic, thanks! Settings good examples++