You are here

class SpamspanExtension in SpamSpan filter 8

Same name and namespace in other branches
  1. 8.2 src/TwigExtension/SpamspanExtension.php \Drupal\spamspan\TwigExtension\SpamspanExtension

Provides the SpamSpan filter function within Twig templates.

Hierarchy

  • class \Drupal\spamspan\TwigExtension\SpamspanExtension extends \Drupal\spamspan\TwigExtension\Twig_Extension

Expanded class hierarchy of SpamspanExtension

1 string reference to 'SpamspanExtension'
spamspan.services.yml in ./spamspan.services.yml
spamspan.services.yml
1 service uses SpamspanExtension
spamspan.twig.spamspan_filter in ./spamspan.services.yml
Drupal\spamspan\TwigExtension\SpamspanExtension

File

src/TwigExtension/SpamspanExtension.php, line 11

Namespace

Drupal\spamspan\TwigExtension
View source
class SpamspanExtension extends \Twig_Extension {

  /**
   * The renderer.
   *
   * @var \Drupal\Core\Render\Renderer
   */
  protected $renderer;

  /**
   * Constructor of SpamSpanExtension.
   *
   * @param \Drupal\Core\Render\Renderer $renderer
   *   The renderer.
   */
  public function __construct(Renderer $renderer) {
    $this->renderer = $renderer;
  }

  /**
   * {@inheritdoc}
   */
  public function getFilters() {
    return [
      new \Twig_SimpleFilter('spamspan', [
        $this,
        'spamSpanFilter',
      ], [
        'is_safe' => [
          'html',
        ],
      ]),
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getName() {
    return 'spamspan.twig_extension';
  }

  /**
   * Applying spamspan filter to the given string.
   *
   * @param string $string
   *   Text, maybe containing email addresses.
   *
   * @return string
   *   The input text with emails replaced by spans
   */
  public function spamSpanFilter($string) {
    $template_attached = [
      '#attached' => [
        'library' => [
          'spamspan/obfuscate',
        ],
      ],
    ];
    $this->renderer
      ->render($template_attached);
    return Xss::filterAdmin(spamspan($string));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SpamspanExtension::$renderer protected property The renderer.
SpamspanExtension::getFilters public function
SpamspanExtension::getName public function
SpamspanExtension::spamSpanFilter public function Applying spamspan filter to the given string.
SpamspanExtension::__construct public function Constructor of SpamSpanExtension.