Custom Core Twig Filter "format_date" conflicts with twig/intl-extra

Created on 5 February 2024, 5 months ago
Updated 10 July 2024, 3 days ago

Problem/Motivation

Some twig functions are not part of Twig core, but come with twig/intl-extra, like:

To be able to use them, I created https://www.drupal.org/project/twig_intl . This simply adds the composer dependency and adds the extension.

This works great, but then I ran into this issue: 🐛 Twig\Error\RuntimeError: The date format "html_date" does not exist Active and looking for the reason, I found a major issue in Drupal core:

new TwigFilter('format_date', [$this->dateFormatter, 'format']),

in https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...
has a naming conflict with the Twig function: https://twig.symfony.com/doc/3.x/filters/format_date.html

Both are using the same name for the |format_date() filter.

Drupal should not overwrite Twigs naming, but (I guess for historic reasons) does.

It's not very widely used in core (https://git.drupalcode.org/search?group_id=2&nav_source=navbar&project_i...), but might be used in contrib!

I have no idea how to solve this cleanly, but Drupal overwriting the Twig method is unexpected and should not be done.
I couldn't find other naming conflicts.

This makes it impossible to use Twig IntlExtension in general, as it produces these conflicts everywhere |format_date() filter is used.

Steps to reproduce

Register Twig IntlExtension as documented on https://twig.symfony.com/doc/3.x/filters/format_date.html or simply use the https://www.drupal.org/project/twig_intl module for that
Visit a page where a template with |format_date() filter is used, for example /admin/reports/translations

Proposed resolution

Resolve the naming conflict by renaming the Drupal core twig filter "format_date" (which is a breaking change) so that the Twig method is not used twice or being overwritten.
Any other ideas?

Merge request link

Remaining tasks

Discuss
Resolve
Test
Release

User interface changes

None

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

11.0 🔥

Component
Theme 

Last updated about 17 hours ago

Created by

🇩🇪Germany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024