HtmlEntityEncode.php in Tamper 8
Namespace
Drupal\tamper\Plugin\TamperFile
src/Plugin/Tamper/HtmlEntityEncode.phpView source
<?php
namespace Drupal\tamper\Plugin\Tamper;
use Drupal\tamper\Exception\TamperException;
use Drupal\tamper\TamperableItemInterface;
use Drupal\tamper\TamperBase;
use Drupal\Component\Utility\Html;
/**
* Plugin implementation for html entity encode.
*
* @Tamper(
* id = "html_entity_encode",
* label = @Translation("HTML entity encode"),
* description = @Translation("This will convert all HTML special characters such as > and & to &gt; and &apm;."),
* category = "Text"
* )
*/
class HtmlEntityEncode extends TamperBase {
/**
* {@inheritdoc}
*/
public function tamper($data, TamperableItemInterface $item = NULL) {
if (!is_string($data)) {
throw new TamperException('Input should be a string.');
}
return Html::escape($data);
}
}
Classes
Name | Description |
---|---|
HtmlEntityEncode | Plugin implementation for html entity encode. |