This issue deals with #2494695: [meta] Deprecate dependency setters and getters on interfaces for \Drupal\language\LanguageNegotiatorInterface.

Issue fork drupal-2494703

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Xano’s picture

Status: Active » Needs review
FileSize
614 bytes
jhodgdon’s picture

Status: Needs review » Needs work

Second line should be indented the way we do on @throws and other tags.

Xano’s picture

Status: Needs work » Needs review
FileSize
616 bytes

You're right, thanks!

Status: Needs review » Needs work

The last submitted patch, 3: drupal_2494703_3.patch, failed testing.

Xano’s picture

Status: Needs work » Needs review
FileSize
616 bytes

Forgot to commit the change locally before making the patch...

jhodgdon’s picture

Component: documentation » language system

Thanks! Tthe formatting looks good to me now.

But I cannot comment on whether the methods should be deprecated, so I think I'll leave the RTBC to someone else... and this is probably not really just Documentation: deprecating a function is not really a docs issue.

Mile23’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Needs review » Needs work
+++ b/core/modules/language/src/LanguageNegotiatorInterface.php
@@ -119,6 +119,9 @@ public function reset();
+   * @deprecated Scheduled for removal in Drupal 9. Use constructor injection
+   *   instead.

Coding standards say: https://www.drupal.org/coding-standards/docs#deprecated

Should say "@deprecated in 8.1.x for removal before Drupal 9.0.x. Inject the current account using the constructor."

Also, we need an issue to add the constructor parameter.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Xano’s picture

Status: Needs work » Needs review
Related issues: +#2758277: Remove LanguageNegotiatorInterface::setCurrentUser()
FileSize
836 bytes
746 bytes

Thanks for the review, @Mile23! I updated the comment, and included a to-do to the newly created follow-up issue as per #7.

Mile23’s picture

Status: Needs review » Reviewed & tested by the community

Patch still applies.

Ossum.

xjm’s picture

Status: Reviewed & tested by the community » Postponed

I think this makes sense to deprecate in 8.2.x for removal in 9.x, to not pollute the API with setters for things that should never be changed after the object is constructed.

When we do deprecations, we should document what usages exist in core, to ensure they are not "wishful deprecations". For this method, based on a grep, it looks to be:

core/modules/language/src/EventSubscriber/LanguageRequestSubscriber.php:      $this->negotiator->setCurrentUser($this->currentUser);
core/modules/language/src/HttpKernel/PathProcessorLanguage.php:    $this->negotiator->setCurrentUser($current_user);
core/modules/language/src/LanguageNegotiator.php:      $instance->setCurrentUser($this->currentUser);
core/modules/language/tests/src/Unit/LanguageNegotiationUrlTest.php:    $method->setCurrentUser($this->user);
core/modules/language/tests/src/Unit/LanguageNegotiationUrlTest.php:    $method->setCurrentUser($this->user);

(Other references appear to be a similarly named method on other objects.) So that's two cases where it's being set by other code, the main implementation itself, and its tests.

Looking at those two usages, in LanguageRequestSubscriber:

public function onKernelRequestLanguage(GetResponseEvent $event) {
  if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
    $request = $event->getRequest();
    $this->negotiator->setCurrentUser($this->currentUser);
    $this->negotiator->reset();
    if ($this->languageManager instanceof ConfigurableLanguageManagerInterface) {
      $this->languageManager->setNegotiator($this->negotiator);
      $this->languageManager->setConfigOverrideLanguage($this->languageManager->getCurrentLanguage());
    }
    // After the language manager has initialized, set the default langcode
    // for the string translations.
    $langcode = $this->languageManager->getCurrentLanguage()->getId();
    $this->translation->setDefaultLangcode($langcode);
  }
}

That's not actually part of the constructor for LanguageRequestSubscriber, even though LanguageRequestSubscriber::__construct() receives both the current user and the negotiator. Why is it being set during a particular method call?

Similarly looking at PathProcessorLanguage:

public function __construct(ConfigFactoryInterface $config, ConfigurableLanguageManagerInterface $language_manager, LanguageNegotiatorInterface $negotiator, AccountInterface $current_user, ConfigSubscriber $config_subscriber) {
  $this->config = $config;
  $this->languageManager = $language_manager;
  $this->negotiator = $negotiator;
  $this->negotiator->setCurrentUser($current_user);
  $this->configSubscriber = $config_subscriber;
}

That one is on construction, so we are good there.

I also think the deprecation needs an example or a slight clarification. I assume this means that LanguageNegotiatorInterface implementations should be defined with the current user as a parameter for their constructors. Can we spell that out a bit more clearly, and possibly give/reference an example?

Finally, I tagged #2494695: [meta] Deprecate dependency setters and getters on interfaces for framework manager review, so we should probably wait on that signoff to proceed with this. (Makes sense to me, but I'm not a framework manager.)

Thanks all!

Xano’s picture

Thanks for taking the time to explain this and for including examples. I'll await the framework manager response in the other issue.

Enjoy your weekend! :)

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

alexpott’s picture

Status: Postponed » Needs work

We now have deprecation procedures that involve triggering a silenced E_USER_DEPRECATED notice and removing all usages in core apart from legacy testing. So there's work to do here.

I think the idea of removing unnecessary API and unnecessary setters is correct.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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