function TestAttributeFilter::process

Same name and namespace in other branches
  1. 8.9.x core/modules/ckeditor/tests/modules/src/Plugin/Filter/TestAttributeFilter.php \Drupal\ckeditor_test\Plugin\Filter\TestAttributeFilter::process()

Overrides FilterInterface::process

File

core/modules/ckeditor/tests/modules/src/Plugin/Filter/TestAttributeFilter.php, line 27

Class

TestAttributeFilter
A filter that adds a test attribute to any configured HTML tags.

Namespace

Drupal\ckeditor_test\Plugin\Filter

Code

public function process($text, $langcode) {
    $document = Html::load($text);
    foreach ($this->settings['tags'] as $tag) {
        $tag_elements = $document->getElementsByTagName($tag);
        foreach ($tag_elements as $tag_element) {
            $tag_element->setAttribute('test_attribute', 'test attribute value');
        }
    }
    return new FilterProcessResult(Html::serialize($document));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.