Problem/Motivation

A time service was added to 8.3.x in #2717207: Add a time service to provide consistent interaction with time()/microtime() and superglobals.

Core code should be updated to remove deprecated uses of REQUEST_TIME and time() and others.

For more informations, see the change record.

This issue deals specifically with replace those calls in plugins and classes with direct container access.

The plugins and classes with direct container access that were identified to have those calls are:

  • \Drupal\comment\CommentForm
  • \Drupal\content_translation\Controller\ContentTranslationController
  • \Drupal\content_translation\ContentTranslationHandler
  • \Drupal\locale\Form\TranslationStatusForm
  • \Drupal\migrate_drupal_ui\Form\ReviewForm
  • \Drupal\system\DateFormatListBuilder
  • \Drupal\system\Form\DateFormatDeleteForm
  • \Drupal\system\Form\DateFormatEditForm
  • \Drupal\toolbar\Controller\ToolbarController
  • \Drupal\user\Controller\UserController

Proposed resolution

- Remove deprecated uses of REQUEST_TIME and time() and others.
- When this issue is successful, there should be no suppressions left in core/phpstan-baseline.neon for the above mentioned classes with the message Call to deprecated constant REQUEST_TIME: Deprecated in drupal:8.3.0 and is removed from drupal:11.0.0. Use \Drupal::time()->getRequestTime();

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3112298

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

mpdonadio created an issue. See original summary.

mpdonadio’s picture

Status: Active » Needs review
StatusFileSize
new52.29 KB

OK, took the patch from 2902895-43.patch

- Isolated just the OO code (well, I tried); this includes classes w/ and w/o access to the container as a starting point

At this point will start going through `git diff --name-only 8.9.x` to isolate by path/namespace revert changes to classes that def don't have container access

mpdonadio’s picture

Title: Replace REQUEST_TIME in OO code w/ access to the container » [PP-1] Replace REQUEST_TIME in OO code w/ access to the container
Status: Needs review » Postponed

Postponing on #3112295: Replace REQUEST_TIME in rest of OO code (except for tests) so there is better starting point. Also thinking that this may really need to two issues to wrangle impact

- container access b/c inheritance
- container access b/c DI

mpdonadio’s picture

Title: [PP-1] Replace REQUEST_TIME in OO code w/ access to the container » [PP-1] Replace REQUEST_TIME in plugins and classes with direct container access
Issue summary: View changes
mpdonadio’s picture

StatusFileSize
new15.79 KB
new36.51 KB

Smaller starting point.

mpdonadio’s picture

Issue summary: View changes
mpdonadio’s picture

StatusFileSize
new32.99 KB
new27.89 KB

Yeah, I know it is postponed...

These don't have create/constructors yet:

core/modules/toolbar/src/Controller/ToolbarController.php
core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php
core/modules/aggregator/src/FeedStorage.php

mpdonadio’s picture

Title: [PP-1] Replace REQUEST_TIME in plugins and classes with direct container access » Replace REQUEST_TIME in plugins and classes with direct container access
Status: Postponed » Needs review
StatusFileSize
new36 KB
new5.22 KB

Let the fails fly!

mpdonadio credited JeroenT.

mpdonadio credited Vlad Bo.

mpdonadio credited pifagor.

mpdonadio credited voleger.

mpdonadio’s picture

Commit credits.

Status: Needs review » Needs work

The last submitted patch, 8: 3112298-08.patch, failed testing. View results

mpdonadio’s picture

Status: Needs work » Needs review
StatusFileSize
new38.87 KB
new5.08 KB

Fixed the new constructs/creates and added a update hook to force rebuild the container.

daffie’s picture

Status: Needs review » Needs work

All the changes in this patch look good. Just one remark:

+++ b/core/modules/system/system.install
@@ -2579,3 +2579,7 @@ function system_update_8901() {
+
+function system_update_8902() {
+  // Nop for testing purposes to force a container rebuild.
+}

Why is this change necessary for this patch?

ravi.shankar’s picture

Status: Needs work » Needs review
StatusFileSize
new38.51 KB
new371 bytes

I have added a patch but not sure if it is enough or not.

Here I have removed the method system_update_8902() because I think it doesn't do anything.

Here again, we need to review the new patch @daffie.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

All the code changes look good.
For me it is RTBC.

longwave’s picture

+++ b/core/modules/aggregator/src/Controller/AggregatorController.php
@@ -21,14 +22,24 @@ class AggregatorController extends ControllerBase {
+    $this->time = $time ?: \Drupal::service('datetime.time');

Do we need to trigger deprecation notices where constructor arguments have been added?

alexpott’s picture

Version: 8.9.x-dev » 9.0.x-dev
Status: Reviewed & tested by the community » Needs work

This needs to be done in D9 first. The patch doesn't apply there.

alexpott’s picture

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

And the answer to #19 is yes which makes this issue 9.1.x really. Especially as REQUEST_TIME is hanging about till D10.

ravi.shankar’s picture

Status: Needs work » Needs review
StatusFileSize
new38.51 KB
new38.02 KB

Here I have added patches for Drupal 8.9.x and Drupal 9.0.x

I have added drupal's version in patch name.

daffie’s picture

@ravi.shankar: Could you post an interdiff.txt file for the changes you have made (for the 9.0 branch as 8.9 branch will never be committed). Thank you for working on this issue.

kristen pol’s picture

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.

andypost’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
+++ b/core/modules/aggregator/src/Controller/AggregatorController.php
@@ -21,14 +22,24 @@ class AggregatorController extends ControllerBase {
+    $this->time = $time ?: \Drupal::service('datetime.time');

this kind of changes require deprecation error about passing null and to be cleared in next major

andypost’s picture

Assigned: mpdonadio » Unassigned
Issue tags: +ContributionWeekend2022

I think part of this changes could be reverted to use request time from current request

+++ b/core/modules/aggregator/src/Controller/AggregatorController.php
@@ -21,14 +22,24 @@ class AggregatorController extends ControllerBase {
+    $this->time = $time ?: \Drupal::service('datetime.time');

+++ b/core/modules/content_translation/src/ContentTranslationHandler.php
@@ -127,6 +137,7 @@ public function __construct(EntityTypeInterface $entity_type, LanguageManagerInt
+    $this->time = $time ?: \Drupal::service('datetime.time');

+++ b/core/modules/system/src/DateFormatListBuilder.php
@@ -32,11 +40,14 @@ class DateFormatListBuilder extends ConfigEntityListBuilder {
+    $this->time = $time ?: \Drupal::service('datetime.time');

+++ b/core/modules/user/src/Controller/UserController.php
@@ -70,13 +78,16 @@ class UserController extends ControllerBase {
+    $this->time = $time ?: \Drupal::service('datetime.time');

+++ b/core/modules/views/src/Plugin/views/argument/Date.php
@@ -70,12 +78,15 @@ class Date extends Formula implements ContainerFactoryPluginInterface {
+    $this->time = $time ?: \Drupal::service('datetime.time');

+++ b/core/modules/views/src/Plugin/views/cache/Time.php
@@ -53,10 +61,13 @@ class Time extends CachePluginBase {
+    $this->time = $time ?: \Drupal::service('datetime.time');

+++ b/core/modules/views/src/Plugin/views/field/Date.php
@@ -44,12 +52,15 @@ class Date extends FieldPluginBase {
+    $this->time = $time ?: \Drupal::service('datetime.time');

should use injection deprecation to explain that service will be required for injection

mondrake’s picture

Issue tags: +PHPStan-0

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.

immaculatexavier’s picture

Status: Needs work » Needs review
StatusFileSize
new37.1 KB

Rerolled patch against 9.5

immaculatexavier’s picture

StatusFileSize
new37.08 KB

Rerolled patch against 9.5

ranjith_kumar_k_u’s picture

StatusFileSize
new36.78 KB
new1.1 KB
mondrake’s picture

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

I'd suggest to target D10 first since this impacts the PHPStan baseline, and then backport.

ankithashetty’s picture

Issue tags: -Needs reroll
StatusFileSize
new27.52 KB
new8.41 KB

Uploading a rerolled patch to 10.0.x version, thanks!

daffie’s picture

Status: Needs review » Needs work

The testbot is not happy. See: https://www.drupal.org/pift-ci-job/2393088

smustgrave’s picture

Version: 10.0.x-dev » 10.1.x-dev
Status: Needs work » Needs review
StatusFileSize
new1.33 KB
new27.79 KB
smustgrave’s picture

StatusFileSize
new7.91 KB
new35.24 KB
smustgrave’s picture

Status: Needs review » Needs work
spokje’s picture

Version: 10.1.x-dev » 9.5.x-dev
Assigned: Unassigned » spokje
spokje’s picture

Version: 9.5.x-dev » 10.1.x-dev
Issue tags: -Drupal 9

Confirmed with @catch what branch this should be against: https://drupal.slack.com/archives/C014CT1CN1M/p1659679942164229

10.1.x it is.

spokje’s picture

Issue summary: View changes
spokje’s picture

Issue summary: View changes
spokje’s picture

Issue summary: View changes
spokje’s picture

Status: Needs work » Needs review
mondrake’s picture

Status: Needs review » Needs work

How painful, it’s way more deprecation tests than actual changes… some comments in MR

spokje’s picture

Status: Needs work » Needs review
spokje’s picture

Assigned: spokje » Unassigned
mondrake’s picture

Status: Needs review » Needs work

some digging in the MR

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

spokje’s picture

mondrake’s picture

Status: Needs review » Needs work

One consideration on whether we can update the property definition with readonly and remove the @var tag - that repeats several times. I see there are alredy some cases where this was committed but would not like to get into coding standards discussions.

Three points I think need more work.

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.

spokje’s picture

Assigned: Unassigned » spokje
spokje’s picture

Issue summary: View changes
spokje’s picture

Status: Needs work » Needs review

- Updated IS
- Updated CR
- Addressed threads from review by @mondrake (thanks!)
- Rebased MR on 11.x

spokje’s picture

Issue summary: View changes
spokje’s picture

Assigned: spokje » Unassigned
mondrake’s picture

Status: Needs review » Reviewed & tested by the community

All good for me, thanks. There are also deprecation tests for missing constructor arguments, which I think are no longer required, but it's a plus.

quietone’s picture

Assigned: Unassigned » quietone
Status: Reviewed & tested by the community » Needs work

I'm triaging RTBC issues. I read the IS and the comments. I didn't find any unanswered questions.

I skimmed the patch and found quite a few out of scope formatting changes which I think these are limited to changing the _construct methods to be multi line. And this change is inconsistent. I then looked at the size of the change and determined it is 65K and, 29 files + 681 − 116 lines. That is well above the recommended patch size of 10-40K. This likely needs to be split into two issues.

I am setting to NW and assigning to myself to remove the out of scope changes to see how much that helps. I will get back to this after a short break.

Oh, I also updated credit.

quietone’s picture

This needed a rebase which I did. I then had to restore a .js file, core/modules/ckeditor5/js/build/drupalMedia.js from 11.x, which I somehow got wrong in the rebase.

Removing the out of scope changes is not sufficient. I am going to look at splitting this into two issues while tests run for the rebase.

quietone’s picture

Title: Replace REQUEST_TIME in plugins and classes with direct container access » Replace REQUEST_TIME in classes with direct container access
Assigned: quietone » Unassigned
Issue summary: View changes
Status: Needs work » Needs review

It is still rather large but I hope this is a bit easier to review now without the plugins. I have updated the title and the CR.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Do we need a followup for the plugins?

Also would it be worth it to create a trait for time? If not changes in scope seem good.

alexpott’s picture

Discussed all the new tests added here with @catch. There's no need to add the constructor tests here. They don't really test anything.

I've updated the MR to deprecate for 10.3.0 and to use autowiring instead of create where this issue was adding a create.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed a9b4000 and pushed to 11.x. Thanks!

alexpott’s picture

After discussion with @catch I decided to delete the change record because it's not adding anything beyond the deprecation message and the constructor documentation.

  • alexpott committed a9b40008 on 11.x
    Issue #3112298 by Spokje, mpdonadio, ravi.shankar, quietone, alexpott,...

Status: Fixed » Closed (fixed)

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