diff --git a/src/Plugin/Tamper/HTMLEntityEncode.php b/src/Plugin/Tamper/HTMLEntityEncode.php new file mode 100644 index 0000000..babeec5 --- /dev/null +++ b/src/Plugin/Tamper/HTMLEntityEncode.php @@ -0,0 +1,60 @@ + 'This will convert all HTML special characters such as > and & to &gt; and &apm;.', + ]; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { + parent::submitConfigurationForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function tamper($data, TamperableItemInterface $item = NULL) { + if (!is_string($data)) { + throw new TamperException('Input should be a string.'); + } + + return Html::escape($data); + } + +} diff --git a/tests/src/Unit/Plugin/Tamper/HTMLEntityEncodeTest.php b/tests/src/Unit/Plugin/Tamper/HTMLEntityEncodeTest.php new file mode 100644 index 0000000..910a990 --- /dev/null +++ b/tests/src/Unit/Plugin/Tamper/HTMLEntityEncodeTest.php @@ -0,0 +1,24 @@ +assertEquals('<html>asdfsadfasf<b>asfasf</b></html>', $plugin->tamper('asdfsadfasfasfasf')); + } + +}