Problem/Motivation

Follow up #2729597: [meta] Replace \Drupal with injected services where appropriate in core

Proposed resolution

Replace all of them with IoC injection where possible

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

jungle created an issue. See original summary.

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.

msuthars’s picture

Assigned: Unassigned » msuthars
msuthars’s picture

StatusFileSize
new72.24 KB

Please review the patch.

msuthars’s picture

Assigned: msuthars » Unassigned
msuthars’s picture

Status: Active » Needs review
msuthars’s picture

Assigned: Unassigned » msuthars
Status: Needs review » Needs work
msuthars’s picture

StatusFileSize
new9.63 KB

\Drupal::cache() with IoC injection where possible. Please review the patch.

msuthars’s picture

Assigned: msuthars » Unassigned
Status: Needs work » Needs review
jungle’s picture

Title: Replace usages of \Drupal::cache() with IoC injection » Replace non-test usages of \Drupal::cache() with IoC injection
Status: Needs review » Needs work

We do this for non-test code under this issue.

Per the parent issue, rescoping this to do it for non-test code.

So i have to set this back to NW, sorry for the change in the middle!

ravi.shankar’s picture

Assigned: Unassigned » ravi.shankar
ravi.shankar’s picture

Assigned: ravi.shankar » Unassigned
Status: Needs work » Needs review
StatusFileSize
new7.91 KB
new1.72 KB

Here I have tried to address comment #10, please review.

jungle’s picture

Status: Needs review » Needs work
+++ b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php
@@ -84,14 +92,17 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
-  public function __construct(array $configuration, $plugin_id, $plugin_definition, CKEditorPluginManager $ckeditor_plugin_manager, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager, RendererInterface $renderer, StateInterface $state) {
+  public function __construct(array $configuration, $plugin_id, $plugin_definition, CKEditorPluginManager $ckeditor_plugin_manager, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager, RendererInterface $renderer, StateInterface $state, CacheBackendInterface $cache) {

Needs Change records. In Drupal 9 this argument needs to be optional. In Drupal 10 we can require it. We need to do something like:

    if ($cache === NULL) {
      @trigger_error('The cache.data service must be passed to ' . __NAMESPACE__ . '\CLASSNAME::__construct(). It was added in drupal:9.1.0 and will be required before drupal:10.0.0. See THE CHANGE RECORD URL', E_USER_DEPRECATED);
      $theme_manager = \Drupal::service('cache.data');
    }
hardik_patel_12’s picture

Status: Needs work » Needs review
StatusFileSize
new8.24 KB
new1.4 KB

Adding change record and deprecation error message in constructor. Kindly review a patch.

jungle’s picture

Status: Needs review » Needs work

@Hardik_Patel_12, thanks for the patch.

+++ b/core/modules/book/src/BookManager.php
@@ -91,12 +91,16 @@
+      @trigger_error('The cache.data service must be passed to ' . __NAMESPACE__ . '\CLASSNAME::__construct(). It was added in drupal:9.1.0 and will be required before drupal:10.0.0. See https://www.drupal.org/node/3160703', E_USER_DEPRECATED);

CLASSNAME here is just a placeholder for example. it should be replaced with a real one, BookManager in this case.

jungle’s picture

+++ b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php
@@ -84,14 +92,17 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
+  public function __construct(array $configuration, $plugin_id, $plugin_definition, CKEditorPluginManager $ckeditor_plugin_manager, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager, RendererInterface $renderer, StateInterface $state, CacheBackendInterface $cache) {

Here missing a BC layer which is simliar to #14

hardik_patel_12’s picture

@jungle , yes i have missed simple changes for CLASSNAME and BC layer for CKEditor file , working on it.

hardik_patel_12’s picture

Status: Needs work » Needs review
StatusFileSize
new8.58 KB
new2.46 KB

Adding points as suggested in #15 and #16 , kindly review a new patch.

Status: Needs review » Needs work

The last submitted patch, 18: 3123232-18.patch, failed testing. View results

hardik_patel_12’s picture

Status: Needs work » Needs review
StatusFileSize
new9.54 KB
new858 bytes

Solving failed test cases , if we want do changes for only non-test file then this test cases will always gone be fail. @jungle can you share your suggestions on this.

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.

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.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

At this time we will need a D10 version of this patch.
Also a rescan of the repo to see if there are other instances that need to be replaced.

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.

hardik_patel_12’s picture

The Book and CKEditor modules are no longer part of the core in version 11.x. Therefore, the patch at #20 is no longer applicable.

quietone’s picture

Status: Needs work » Closed (outdated)

I agree this is outdated. Anyone wanting these changes should open an issue in the Book contrib module or the CKEditor contrib module.