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()

Performs the filter processing.

Parameters

string $text: The text string to be filtered.

string $langcode: The language code of the text to be filtered.

Return value

\Drupal\filter\FilterProcessResult The filtered text, wrapped in a FilterProcessResult object, and possibly with associated assets, cacheability metadata and placeholders.

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.