Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 294882

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

$
0
0

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: #3419285: Twig\Error\RuntimeError: The date format "html_date" does not exist 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?

Remaining tasks

Discuss
Resolve
Test
Release

User interface changes

None

API changes

Data model changes

Release notes snippet


Viewing all articles
Browse latest Browse all 294882

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>