Repository navigation
Use CoreExtension's date methods instead of Twig's deprecated date helpers - #1600
Conversation
The date() function and |date filter called twig_date_converter() and twig_date_format_filter(), deprecated since Twig 3.9; every template using |date logged a deprecation per render. Call CoreExtension::convertDate() and ::formatDate(), which those helpers wrap (Winter requires twig/twig ^3.21). date() with no argument also passed null to DateTime::makeCarbon(), whose preg_match() deprecates null; pass 'now' instead (makeCarbon already treated null as now, so the output is unchanged). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GMxdgmMTLxfALWSSvtBYYR
|
No actionable comments were generated in the recent review. WalkthroughThe Twig Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Merge Risk:
|
The CMS tags fixture already renders everything through a controller and fails on any deprecation, in both the normal and use_yield environments. Add a line exercising date() (with and without an argument) and |date on a string, a Carbon instance and a DateInterval, and drop DateTest. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GMxdgmMTLxfALWSSvtBYYR
Summary
Winter's
date()Twig function and|datefilter (modules/system/ServiceProvider.php) calltwig_date_converter()andtwig_date_format_filter(). Twig deprecated both helpers in 3.9, so every template that uses|datelogs this on every render:The helpers only forward to
CoreExtension::convertDate()andCoreExtension::formatDate(). This PR calls those methods directly. Winter requirestwig/twig ^3.21, so they're always available, and the output is identical.Removing those two calls exposed one more deprecation.
{{ date() }}passednulltoDateTime::makeCarbon(), andmakeCarbon()'spreg_match()deprecates anullsubject. It now passes'now'.makeCarbon()already resolvednullto now (throughCarbon::parse(null)), so the result is the same.Follow-up to #1595, which fixed the tag, filter and list deprecations from the same production logs but not these two helpers.
Side note, not changed here: in the
date()function, theis_null($value) || $value === 'now'branch can never run, because$valuehas already been replaced by aDateTimeat that point.Testing
modules/cms/tests/fixtures/twig/tags.htm, from Fix Twig 3.x and PHP 8.3 deprecations from core Twig tags, filters and lists #1595) gets a line 20. It callsdate()with and without an argument, and applies|dateto a string, a Carbon instance and aDateInterval.TagsTestpasses in the last two as template variables. That test already renders the fixture through a CMS controller, in both the normal anduse_yieldenvironments, and fails on any deprecation.TagsTesttests fail ontwig_date_converter,twig_date_format_filterandpreg_match(): Passing null.modules/systemsuite: run locally ondevelopwith and without the change. It reports the same set of errors and failures, all from my local environment.🤖 Generated with Claude Code
https://claude.ai/code/session_01GMxdgmMTLxfALWSSvtBYYR
Summary by CodeRabbit