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.

kunalgautam’s picture

Assigned: Unassigned » kunalgautam
kunalgautam’s picture

StatusFileSize
new30.92 KB
kunalgautam’s picture

Assigned: kunalgautam » Unassigned
Status: Active » Needs review
jungle’s picture

Title: Replace usages of \Drupal::token() with IoC injection » Replace non-test usages of \Drupal::token() 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!

hardik_patel_12’s picture

Status: Needs work » Needs review
StatusFileSize
new2.96 KB

Replacing \Drupal::token() with IoC injection for WidgetBase.php file.

git grep -nri '\Drupal::token()' core | grep -v .module | grep -iv test.php | grep -iv .inc | grep -iv trait.php| grep -iv .api.php | grep -v authorize.php | grep -iv testbase.php | grep -v '//' | grep -v '*' | grep -v .theme | grep -v '/tests/'

core/lib/Drupal/Core/Field/WidgetBase.php:602:    return FieldFilteredMarkup::create(\Drupal::token()->replace($this->fieldDefinition->getDescription()));

Kindly review.

jungle’s picture

Status: Needs review » Needs work

@Hardik_Patel_12, thanks for working on this!

+++ b/core/lib/Drupal/Core/Field/WidgetBase.php
@@ -46,19 +54,33 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface,
+      @trigger_error('Calling ' . __METHOD__ . ' without the $token argument is deprecated in drupal:9.1.0 and will be required in drupal:10.0.0. See https://www.drupal.org/node/3161197', E_USER_DEPRECATED);

Would be bette not just telling the __METHOD__, suggestion: __NAMESPACE__ . '\WidgetBase::__construct()

jungle’s picture

The CR title "widgetBase constructor injecting a token service ($token) as an argument"

widgetBase -> WidgetBase

jungle’s picture

The CR:

\Drupal\Core\Field\WidgetBase::__construct() adds an $token argument. This will be required in Drupal 10.

Add would be better wrapping \Drupal\Core\Field\WidgetBase::__construct() and $token with the HTML tag code

hardik_patel_12’s picture

Status: Needs work » Needs review
StatusFileSize
new2.99 KB
new849 bytes

CR and deprecation message updated.

The last submitted patch, 7: 3123229-7.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 11: 3123229-11.patch, failed testing. View results

snehalgaikwad’s picture

Assigned: Unassigned » snehalgaikwad
snehalgaikwad’s picture

Assigned: snehalgaikwad » Unassigned
Status: Needs work » Needs review
StatusFileSize
new3.8 KB
new1 KB

Replaced \Drupal::token() from two more places.

hardik_patel_12’s picture

Status: Needs review » Needs work

Last patch failed to apply.

snehalgaikwad’s picture

Status: Needs work » Needs review
StatusFileSize
new3.7 KB
hardik_patel_12’s picture

StatusFileSize
new2.99 KB

Last patch failed to apply , re-rolling the patch.

Status: Needs review » Needs work

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

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.

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.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.