function TwigExtension::getFilters

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Template/TwigExtension.php \Drupal\Core\Template\TwigExtension::getFilters()
  2. 8.9.x core/lib/Drupal/Core/Template/TwigExtension.php \Drupal\Core\Template\TwigExtension::getFilters()
  3. 10 core/lib/Drupal/Core/Template/TwigExtension.php \Drupal\Core\Template\TwigExtension::getFilters()

File

core/lib/Drupal/Core/Template/TwigExtension.php, line 117

Class

TwigExtension
A class providing Drupal Twig extensions.

Namespace

Drupal\Core\Template

Code

public function getFilters() {
    return [
        // Translation filters.
new TwigFilter('t', 't', [
            'is_safe' => [
                'html',
            ],
        ]),
        new TwigFilter('trans', 't', [
            'is_safe' => [
                'html',
            ],
        ]),
        // The "raw" filter is not detectable when parsing "trans" tags. To detect
        // which prefix must be used for translation (@, !, %), we must clone the
        // "raw" filter and give it identifiable names. These filters should only
        // be used in "trans" tags.
        // @see TwigNodeTrans::compileString()
new TwigFilter('placeholder', [
            $this,
            'escapePlaceholder',
        ], [
            'is_safe' => [
                'html',
            ],
            'needs_environment' => TRUE,
        ]),
        // Replace twig's escape filter with our own.
new TwigFilter('drupal_escape', [
            $this,
            'escapeFilter',
        ], [
            'needs_environment' => TRUE,
            'is_safe_callback' => 'twig_escape_filter_is_safe',
        ]),
        // Implements safe joining.
        // @todo Make that the default for |join? Upstream issue:
        //   https://github.com/fabpot/Twig/issues/1420
new TwigFilter('safe_join', [
            $this,
            'safeJoin',
        ], [
            'needs_environment' => TRUE,
            'is_safe' => [
                'html',
            ],
        ]),
        // Array filters.
new TwigFilter('without', [
            $this,
            'withoutFilter',
        ]),
        // CSS class and ID filters.
new TwigFilter('clean_class', '\\Drupal\\Component\\Utility\\Html::getClass'),
        new TwigFilter('clean_id', '\\Drupal\\Component\\Utility\\Html::getId'),
        new TwigFilter('clean_unique_id', '\\Drupal\\Component\\Utility\\Html::getUniqueId'),
        new TwigFilter('add_class', [
            $this,
            'addClass',
        ]),
        new TwigFilter('set_attribute', [
            $this,
            'setAttribute',
        ]),
        // This filter will render a renderable array to use the string results.
new TwigFilter('render', [
            $this,
            'renderVar',
        ]),
        new TwigFilter('format_date', [
            $this->dateFormatter,
            'format',
        ]),
        // Add new theme hook suggestions directly from a Twig template.
new TwigFilter('add_suggestion', [
            $this,
            'suggestThemeHook',
        ]),
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.