You are here

public function TwigTweakExtension::getFilters in Twig Tweak 3.x

Same name and namespace in other branches
  1. 3.1.x src/TwigTweakExtension.php \Drupal\twig_tweak\TwigTweakExtension::getFilters()

File

src/TwigTweakExtension.php, line 100

Class

TwigTweakExtension
Twig extension with some useful functions and filters.

Namespace

Drupal\twig_tweak

Code

public function getFilters() : array {
  $filters = [
    new TwigFilter('token_replace', [
      self::class,
      'tokenReplaceFilter',
    ]),
    new TwigFilter('preg_replace', [
      self::class,
      'pregReplaceFilter',
    ]),
    new TwigFilter('image_style', [
      self::class,
      'imageStyleFilter',
    ]),
    new TwigFilter('transliterate', [
      self::class,
      'transliterateFilter',
    ]),
    new TwigFilter('check_markup', 'check_markup'),
    new TwigFilter('format_size', 'format_size'),
    new TwigFilter('truncate', [
      Unicode::class,
      'truncate',
    ]),
    new TwigFilter('view', [
      self::class,
      'viewFilter',
    ]),
    new TwigFilter('with', [
      self::class,
      'withFilter',
    ]),
    new TwigFilter('children', [
      self::class,
      'childrenFilter',
    ]),
    new TwigFilter('file_uri', [
      self::class,
      'fileUriFilter',
    ]),
    new TwigFilter('file_url', [
      self::class,
      'fileUrlFilter',
    ]),
    new TwigFilter('translation', [
      self::class,
      'entityTranslation',
    ]),
    new TwigFilter('cache_metadata', [
      self::class,
      'CacheMetadata',
    ]),
  ];
  if (Settings::get('twig_tweak_enable_php_filter')) {
    $filters[] = new TwigFilter('php', [
      self::class,
      'phpFilter',
    ], [
      'needs_context' => TRUE,
    ]);
  }
  $this->moduleHandler
    ->alter('twig_tweak_filters', $filters);
  $this->themeManager
    ->alter('twig_tweak_filters', $filters);
  return $filters;
}