Problem/Motivation

As part of #2999721: [META] Deprecate the legacy include files before Drupal 9, deprecate format_date()

Proposed resolution

Replace with calls to DateFormatterInterface::format().

  • In tests, replace all format_date() calls with $this->container->get('date.formatter')->format() calls.
  • In procedural code, replace all format_date() calls with \Drupal::service('date.formatter')->format() calls.
  • In classes, inject the date formatter service from the container, and use it.

Remaining tasks

None.

User interface changes

None.

API changes

Where necessary constructors are changed.

Data model changes

None.

Comments

jcnventura created an issue. See original summary.

jcnventura’s picture

StatusFileSize
new41.43 KB

This patch replaces all format_date() calls in tests with calls to $this->container->get('date.formatter')->format().

jcnventura’s picture

Status: Active » Needs review
jcnventura’s picture

jcnventura’s picture

StatusFileSize
new810 bytes
new42.39 KB

Forgot one in the midst of these changes to other parts of core.

jcnventura’s picture

Issue summary: View changes
quietone’s picture

StatusFileSize
new42.88 KB
new15.31 KB

This adds $date_formatter = $this->container->get('date.formatter') in a few more places. Including adding it to FilterDateTest::setup() since the date formatter is used in most of its methods. Hope that is useful.

andypost’s picture

Status: Needs review » Needs work
+++ b/core/modules/locale/tests/src/Functional/LocaleUpdateInterfaceTest.php
@@ -111,7 +111,10 @@ public function testInterface() {
+      '@date' => $this->container->get('date.formatter')->format(REQUEST_TIME, 'html_date'),

while thisline changed it needs to use date service instead of deprecated REQUEST_TIME

fenstrat’s picture

Status: Needs work » Needs review
StatusFileSize
new43.39 KB
new1.55 KB

Addresses #8.

alexpott’s picture

Status: Needs review » Closed (duplicate)

The splitting of issues like

is against the advice of our scoping recommendations. Let's not do this. See https://www.drupal.org/core/scope

I'm going to combine all the issues to the earliest issue - #3008446: Complete the deprecation of format_date()

alexpott’s picture

Status: Closed (duplicate) » Needs work
alexpott’s picture

Title: Deprecate format_date() in tests » Deprecate format_date()
Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new82.84 KB

Combining all the patches. All the people who have worked on the other issues are already credited here.

alexpott’s picture

StatusFileSize
new2.72 KB
new83.93 KB

A few minor improvements

alexpott’s picture

StatusFileSize
new1.32 KB
new83.61 KB
+++ b/core/modules/views/src/Plugin/views/argument/DayDate.php
@@ -20,22 +20,25 @@ class DayDate extends Date {
   /**
-   * Provide a link to the next level of the view
+   * {@inheritdoc}
    */
...
   /**
-   * Provide a link to the next level of the view
+   * {@inheritdoc}
    */
...
+  /**
+   * {@inheritdoc}
+   */

+++ b/core/modules/views/src/Plugin/views/argument/FullDate.php
@@ -20,18 +20,18 @@ class FullDate extends Date {
   /**
-   * Provide a link to the next level of the view
+   * {@inheritdoc}
    */
...
   /**
-   * Provide a link to the next level of the view
+   * {@inheritdoc}
    */

+++ b/core/modules/views/src/Plugin/views/argument/MonthDate.php
@@ -20,21 +20,24 @@ class MonthDate extends Date {
   /**
-   * Provide a link to the next level of the view
+   * {@inheritdoc}
    */
   public function summaryName($data) {
...
   /**
-   * Provide a link to the next level of the view
+   * {@inheritdoc}
    */
...
+  /**
+   * {@inheritdoc}
+   */

These changes are of questionable scope. However I think it is okay for some of them to remain because, where we are changing the return of the method, updating the docblock is okay. But the changes to add a docblock to summaryArgument are not in scope.

alexpott’s picture

Title: Deprecate format_date() » Complete the deprecation of format_date()

The last submitted patch, 12: 3008446-12.patch, failed testing. View results

voleger’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/modules/content_translation/src/ContentTranslationHandler.php
@@ -503,13 +515,17 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, En
-      $date = $new_translation ? REQUEST_TIME : $metadata->getCreatedTime();
+      $request_time = \Drupal::time()->getRequestTime();
+      $date = $new_translation ? $request_time : $metadata->getCreatedTime();

+++ b/core/modules/locale/tests/src/Functional/LocaleUpdateInterfaceTest.php
@@ -104,14 +104,17 @@ public function testInterface() {
-    $status['drupal']['de']->files['local']->timestamp = REQUEST_TIME;
+    $status['drupal']['de']->files['local']->timestamp = \Drupal::time()->getRequestTime();

That's a little bit out of scope. But I'm okay with that, as there too much not replaced REQUEST_TIME yet.

Anyway tests are green, and all calls and mentions are properly replaced. +1 for RTBC

alexpott’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new7.14 KB
new83.44 KB

Yeah the out-of-scope changes kind of bother me. We really only should be changing things directly in-scope. Especially in run-time code. I realise this was requested in #8 but that it incorrect. Scoped issues that address only one thing are important because when and if things need rolling-back or discussed at a later date makes it easier to make sense. The changes to system.tokens.inc show why this is important - we were still using REQUEST_TIME in this file after #14 - inconsistencies like this become confusing.

If this patch was ready to go I would say that we should just go forward and not fix REUQEST_TIME, BUT we have no deprecation test which is required because:

  • To ensure the deprecation is triggered as expected
  • To ensure we don't break format_date() as a later date in the Drupal 8 cycle.
voleger’s picture

Looks much better this time. The legacy test also looks good. +1 for rtbc.

voleger’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

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

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new83.47 KB
alexpott’s picture

voleger’s picture

Status: Needs review » Reviewed & tested by the community

Great! RTBC again

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 31f9ebf and pushed to 8.7.x. Thanks!

Also thanks for keeping the scope in check here, especially for a New Years Day commit.

  • catch committed 31f9ebf on 8.7.x
    Issue #3008446 by alexpott, jcnventura, fenstrat, quietone, voleger,...

Status: Fixed » Closed (fixed)

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