Replace calls to format_date() with Drupal::service('date.formatter')

Change record: https://www.drupal.org/node/1876852

Comments

maliknaik created an issue. See original summary.

maliknaik’s picture

Status: Active » Needs review
StatusFileSize
new2.69 KB

Status: Needs review » Needs work

The last submitted patch, 2: 3049638.patch, failed testing. View results

maliknaik’s picture

StatusFileSize
new2.72 KB
maliknaik’s picture

Status: Needs work » Needs review
jonathan1055’s picture

Status: Needs review » Needs work

HI maliknaik
Thanks for the patch. Are you responding to #3042677: Drupal 9 Deprecated Code Report for Scheduler? If so, can you add that as a parent issue and add a comment on that issue, otherwise someone else could duplicate the work.

Also can you remove the part of your patch which covers drupal::url as that is already dealt with in #3048600: Drupal::url() is deprecated, replace with \Drupal\Core\Url object

Thirdly, can you give a link to a change record on drupal.org so that we know exactly what was deprecated and in what release.

Thanks a lot
Jonathan

maliknaik’s picture

Title: Replace call to deprecated functions format_date and \Drupal::url » Replace call to deprecated function format_date
StatusFileSize
new1.53 KB

@jonathan1055 Here is the updated patch and the link to the change record Date formats API changes

maliknaik’s picture

Status: Needs work » Needs review
jonathan1055’s picture

Issue summary: View changes

Thanks for the patch. All works fine.

However I can see that we are using Drupal::service('date.formatter') in six test files already. I think I will add this to the testBase first, then it is simpler to change the test files.

Interesting that the change record does not actually say that format_date() is deprecated. Are there any other doc pages you can find which say when the function will be deprecated?

jonathan1055’s picture

StatusFileSize
new3.41 KB

Here's a patch which adds the dateFormatter service to SchedulerTestBase and uses that instead of creating $date_formatter in the actual test. I have also made the change in MetaInformation test. There are five other tests which would need this improvement, if you want to do those too?

  • jonathan1055 committed 15c158f on 8.x-1.x
    Issue #3049638 by maliknaik, jonathan1055: Replace call to deprecated...
jonathan1055’s picture

Assigned: maliknaik » Unassigned
Status: Needs review » Fixed

Thanks. Committed.

Now that I've added the dateformatter object to SchedulerBrowserTestBase a separate issue can be opened to change the other four tests to use $this->dateFormatter

edit: Opened #3054372: Replace Drupal::service('date.formatter') with $this->dateFormatter in tests

Status: Fixed » Closed (fixed)

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