public function TestAttributeFilter::process in Drupal 9
Same name and namespace in other branches
- 8 core/modules/ckeditor/tests/modules/src/Plugin/Filter/TestAttributeFilter.php \Drupal\ckeditor_test\Plugin\Filter\TestAttributeFilter::process()
- 10 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
See also
\Drupal\filter\FilterProcessResult
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\FilterCode
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));
}