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

Command icon 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

joachim created an issue. See original summary.

joachim’s picture

Issue summary: View changes

Aguillet made their first commit to this issue’s fork.

govind_giri_goswami’s picture

Yes, 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.

Keshav Patel made their first commit to this issue’s fork.

keshav patel’s picture

Status: Active » Needs review

Replaced Drupal\locale\Locale::config() with \Drupal::service('locale.config_manager'), Verified the Checks Using core/scripts/dev/commit-code-check.sh --cached (All Checks Passed). Please Review

smustgrave’s picture

Status: Needs review » Needs work

Don't see the deprecation.

karanpagare made their first commit to this issue’s fork.

karanpagare’s picture

Status: Needs work » Needs review

Deprecated the config() method.

joachim’s picture

Status: Needs review » Needs work

> 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.

magaki made their first commit to this issue’s fork.

magaki’s picture

Status: Needs work » Needs review

I reverted the removing Locale::config and updated the documentation.
The unittest is failing because I added the @deprecated tag to the documentation but the %deprecation-version% and %removal-version% doesn't exist.
However, I don't know them.
Please review it.

> phpcs --standard=core/phpcs.xml.dist --parallel="$( (nproc || sysctl -n hw.logicalcpu || echo 4) 2>/dev/null)" -- '--report-full' '--report-summary' '--report-\Micheh\PhpCodeSniffer\Report\Gitlab=phpcs-quality-report.json'
FILE: /builds/issue/drupal-3422915/core/modules/locale/src/Locale.php
--------------------------------------------------------------------------------
FOUND 2 ERRORS AND 1 WARNING AFFECTING 3 LINES
--------------------------------------------------------------------------------
 19 | ERROR   | The text '@deprecated Use
    |         | \Drupal::service('locale.config_manager') instead.' does not
    |         | match the standard format: @deprecated in %deprecation-version%
    |         | and is removed from %removal-version%. %extra-info%.
 21 | WARNING | The @see url
    |         | '\Drupal\Core\TypedData\TypedDataManager::create()' does not
    |         | match the standard: http(s)://www.drupal.org/node/n or
    |         | http(s)://www.drupal.org/project/aaa/issues/n
 24 | ERROR   | The trigger_error message '__METHOD__ () is deprecated. Use
    |         | \Drupal::service(\'locale.config_manager\') instead.' does not
    |         | match the strict standard format: %thing% is deprecated in
    |         | %deprecation-version% and is removed from %removal-version%.
    |         | %extra-info%. See %cr-link%
smustgrave’s picture

Status: Needs review » Needs work

Deprecation isn’t correct. Recommend looking through the repo for examples of deprecation format

magaki’s picture

I 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

smustgrave’s picture

Seems 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.

smustgrave’s picture

Good work with the test!

magaki’s picture

Status: Needs work » Needs review
smustgrave’s picture

On this ticket whaat happens if you click add change notice?

smustgrave’s picture

If that doesn’t work will try and help on Monday

joachim’s picture

> pull the latest 11.x code into this branch

Please rebase rather than merge!

magaki’s picture

I 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.

magaki’s picture

Thank you for confirming my account.
I could create a new change records.
https://www.drupal.org/node/3437110

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Deprecation CR looks good.

Thanks for updating link in code too.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Thanks 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.

magaki’s picture

Status: Needs work » Needs review
  • Added documentation about the deprecation of the Locale class.
  • Removed unnecessary periods.
  • About using $localConfigManager as a temporary variable of Locale::config()
    • Removed $localConfigManager if it was only used once.
    • Renamed to $locale_config_manager if it was used more than once.

Please review it

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Deprecation seems good now. Marking this so we don't miss the 10.3 boat.

catch’s picture

Status: Reviewed & tested by the community » Needs work

If 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.

joachim’s picture

Status: Needs work » Needs review

Easier 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

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Looks ready again

alexpott changed the visibility of the branch 3422915-10.2.deprecate-drupallocalelocale to hidden.

alexpott changed the visibility of the branch 11.x to hidden.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I'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() over Drupal::service()

joachim’s picture

Assigned: Unassigned » joachim

> This file needs to be removed - this is the 11.x branch.

Ok something went WTF with my branches. I'll fix.

joachim’s picture

Assigned: joachim » Unassigned
Status: Needs work » Needs review

I'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?

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Rebased the 10.3.x MR as the failure appeared to be a random Umami bug.

Believe all feedback has been addressed

  • alexpott committed dc9a4c53 on 10.3.x
    Issue #3422915 by magaki, karanpagare, joachim, alexpott, Keshav Patel,...
alexpott’s picture

Version: 11.x-dev » 10.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed dc9a4c5 and pushed to 10.3.x. Thanks!
Committed 4c93088 and pushed to 11.x. Thanks!

  • alexpott committed 4c93088c on 11.x
    Issue #3422915 by magaki, karanpagare, joachim, alexpott, Keshav Patel,...

  • alexpott committed 4c93088c on 11.0.x
    Issue #3422915 by magaki, karanpagare, joachim, alexpott, Keshav Patel,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.