public function DefaultWordfilterProcess::filterWords in Wordfilter 8.2
Provides filtering of words by the given Wordfilter configuration.
Parameters
string $text: The text to filter.
\Drupal\wordfilter\Entity\WordfilterConfigurationInterface $wordfilter_config: The Wordfilter configuration to use during the filtering process.
string $langcode: (Optional) The language code.
Return value
string The filtered text.
Overrides WordfilterProcessInterface::filterWords
File
- src/
Plugin/ WordfilterProcess/ DefaultWordfilterProcess.php, line 21
Class
- DefaultWordfilterProcess
- Plugin annotation @WordfilterProcess( id = "default", label = @Translation("Direct substitution (default)"), description = @Translation("All specified filter words will be directly replaced with the specified substitution text by using a simple…
Namespace
Drupal\wordfilter\Plugin\WordfilterProcessCode
public function filterWords($text, WordfilterConfigurationInterface $wordfilter_config, $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED) {
foreach ($wordfilter_config
->getItems() as $item) {
$filter_words = $item
->getFilterWords();
$filter_words = $this
->prepareWordsForRegex($filter_words);
$filter_pattern = '/' . implode('|', $filter_words) . '/i';
$substitute = Xss::filterAdmin($item
->getSubstitute());
$text = preg_replace($filter_pattern, $substitute, $text);
}
return $text;
}