Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. EscaperExtension.php

function EscaperExtension::setEscaper

Defines a new escaper to be used via the escape filter.

Parameters

string $strategy The strategy name that should be used as a strategy in the escape call:

callable(Environment, string, string): string $callable A valid PHP callable:

Deprecated

since Twig 3.10

File

vendor/twig/twig/src/Extension/EscaperExtension.php, line 127

Class

EscaperExtension

Namespace

Twig\Extension

Code

public function setEscaper($strategy, callable $callable) {
    trigger_deprecation('twig/twig', '3.10', 'The "%s()" method is deprecated, use the "Twig\\Runtime\\EscaperRuntime::setEscaper()" method instead (be warned that Environment is not passed anymore to the callable).', __METHOD__);
    if (!isset($this->environment)) {
        throw new \LogicException(\sprintf('You must call "setEnvironment()" before calling "%s()".', __METHOD__));
    }
    $this->escapers[$strategy] = $callable;
    $callable = function ($string, $charset) use ($callable) {
        return $callable($this->environment, $string, $charset);
    };
    $this->escaper
        ->setEscaper($strategy, $callable);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal