Problem/Motivation
Drupal\locale\Locale::config() is just a wrapper method that returns a service.
It doesn't serve any useful purpose and makes code more confusing to read. It's clearer to see what's going on when you see a service being called than a mystery static method.
Steps to reproduce
Proposed resolution
Deprecate the config() method.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Issue fork drupal-3422915
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
joachim commentedComment #4
govind_giri_goswami commentedYes, we can remove the Drupal\locale\Locale::config() method because in files such as core/modules/locale/locale.bulk.inc and core/modules/locale/tests/src/Functional/LocaleConfigTranslationImportTest.php, the function of the injected service is directly called instead of going through the config() function. Therefore, it's more efficient to directly utilize the injected service in these files.
Comment #7
keshav patel commentedReplaced
Drupal\locale\Locale::config()with\Drupal::service('locale.config_manager'), Verified the Checks Usingcore/scripts/dev/commit-code-check.sh --cached(All Checks Passed). Please ReviewComment #8
smustgrave commentedDon't see the deprecation.
Comment #10
karanpagare commentedDeprecated the config() method.
Comment #11
joachim commented> Deprecated the config() method.
Deprecating doesn't meant removing it -- we have to keep it in, and add a trigger_error() to it so that any callers are told that they need to updated their code.
Comment #13
magakiI reverted the removing
Locale::configand updated the documentation.The unittest is failing because I added the
@deprecatedtag to the documentation but the%deprecation-version%and%removal-version%doesn't exist.However, I don't know them.
Please review it.
Comment #14
smustgrave commentedDeprecation isn’t correct. Recommend looking through the repo for examples of deprecation format
Comment #15
magakiI modified the documentation according to Drupal deprecation policy and added its test.
Please review it.
The test fails, but it doesn't seem to be related to the changes.
https://git.drupalcode.org/issue/drupal-3422915/-/jobs/1193931 -> test summary
Comment #16
smustgrave commentedSeems small enough to deprecate in 10.3 for removal in 11.
Will need a change record and the link points to that. Can be simple and would search the change record list for other deprecation examples for to write one (usually just a sentence or two)
And for the random failure would try and pull the latest 11.x code into this branch. That’s resolved it on other issues.
Comment #17
smustgrave commentedGood work with the test!
Comment #18
magakiComment #20
smustgrave commentedOn this ticket whaat happens if you click add change notice?
Comment #21
smustgrave commentedIf that doesn’t work will try and help on Monday
Comment #22
joachim commented> pull the latest 11.x code into this branch
Please rebase rather than merge!
Comment #23
magakiI made a mistake in rebase once, so I force pushed the pre-rebase, updated the 11.x branch of the repository to the latest, and rebased the branch to on top of that.
Comment #24
magakiThank you for confirming my account.
I could create a new change records.
https://www.drupal.org/node/3437110
Comment #25
smustgrave commentedDeprecation CR looks good.
Thanks for updating link in code too.
Comment #26
alexpottThanks for working on this everyone!
Some unrelated change snuck into the MR - probably due to an IDE - we need to remove that. Also I don;t think this issue should be introducing a camel cased variable everywhere. I
think we should replace Locale::config() we \Drupal::service('locale.config_manager') and be done.
Also we need to add a deprecation to the class body so that we can safely remove the class in 11.x. I. think this is fine here because this in not a plugin and therefore won't trigger unexpected deprecations only good ones.
Comment #27
magakiLocaleclass.$localConfigManageras a temporary variable ofLocale::config()$localConfigManagerif it was only used once.$locale_config_managerif it was used more than once.Please review it
Comment #28
smustgrave commentedDeprecation seems good now. Marking this so we don't miss the 10.3 boat.
Comment #29
catchIf we're doing this for removal in 11.0.0, we should also have an 11.x-specific MR here that does the removal directly without the bc layer / test coverage etc. The existing MR should be re-targeted/rebased for 10.3.x
Haven't been asking for this previously, but we're adding new deprecations nearly as quickly as we're removing them still, so think we need to start using that workflow.
Comment #31
joachim commentedEasier to make the current MR for 11.x the one without the deprecation, and make a new branch and MR for 10.3 with the current code.
- https://git.drupalcode.org/project/drupal/-/merge_requests/7667 -- on 10.3.x, updates uses, adds deprecation
- https://git.drupalcode.org/project/drupal/-/merge_requests/6948 -- on 11.x, updates uses, removes the code
Comment #32
andypostLooks ready again
Comment #36
alexpottI've fixed up the 10.3.x MR so that the test is correct - this does not return a \Drupal\Core\Config\ConfigManager object it returns a \Drupal\locale\LocaleConfigManager object.
Unfortunately the 11.x MR does not do the removal so that needs work.
Also we use
\Drupal::service()overDrupal::service()Comment #37
joachim commented> This file needs to be removed - this is the 11.x branch.
Ok something went WTF with my branches. I'll fix.
Comment #38
joachim commentedI've fixed the file removals in the 11.x MR. I've no idea how they got lost / and maybe on the wrong branch!
I'm confused about whether there's anything else to fix -- @alexpott you seem to have applied the suggested changes to both branches?
Comment #39
smustgrave commentedRebased the 10.3.x MR as the failure appeared to be a random Umami bug.
Believe all feedback has been addressed
Comment #41
alexpottCommitted dc9a4c5 and pushed to 10.3.x. Thanks!
Committed 4c93088 and pushed to 11.x. Thanks!