Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[yaffs-website] / web / core / modules / ckeditor / tests / modules / src / Plugin / Filter / TestAttributeFilter.php
1 <?php
2
3 namespace Drupal\ckeditor_test\Plugin\Filter;
4
5 use Drupal\Component\Utility\Html;
6 use Drupal\filter\FilterProcessResult;
7 use Drupal\filter\Plugin\FilterBase;
8
9 /**
10  * A filter that adds a test attribute to any configured HTML tags.
11  *
12  * @Filter(
13  *   id = "test_attribute_filter",
14  *   title = @Translation("Test Attribute Filter"),
15  *   type = Drupal\filter\Plugin\FilterInterface::TYPE_TRANSFORM_REVERSIBLE,
16  *   settings = {
17  *     "tags" = {},
18  *   },
19  *   weight = -10
20  * )
21  */
22 class TestAttributeFilter extends FilterBase {
23
24   /**
25    * {@inheritdoc}
26    */
27   public function process($text, $langcode) {
28     $document = Html::load($text);
29     foreach ($this->settings['tags'] as $tag) {
30       $tag_elements = $document->getElementsByTagName($tag);
31       foreach ($tag_elements as $tag_element) {
32         $tag_element->setAttribute('test_attribute', 'test attribute value');
33       }
34     }
35     return new FilterProcessResult(Html::serialize($document));
36   }
37
38 }