class SpamspanExtension in SpamSpan filter 8
Same name and namespace in other branches
- 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'
1 service uses SpamspanExtension
File
- src/
TwigExtension/ SpamspanExtension.php, line 11
Namespace
Drupal\spamspan\TwigExtensionView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SpamspanExtension:: |
protected | property | The renderer. | |
SpamspanExtension:: |
public | function | ||
SpamspanExtension:: |
public | function | ||
SpamspanExtension:: |
public | function | Applying spamspan filter to the given string. | |
SpamspanExtension:: |
public | function | Constructor of SpamSpanExtension. |