public function BlockquoteFilter::process in Bootstrap Utilities - Text editor filters 8
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
- src/
Plugin/ Filter/ BlockquoteFilter.php, line 24
Class
- BlockquoteFilter
- Add Bootstrap Class to any blockquote.
Namespace
Drupal\bootstrap_utilities\Plugin\FilterCode
public function process($text, $langcode) {
$result = new FilterProcessResult($text);
if (stristr($text, 'blockquote') !== FALSE) {
$setting_classes = [];
$setting_classes[] = 'blockquote';
$dom = Html::load($text);
$xpath = new \DOMXPath($dom);
$blockquote_elements = $xpath
->query('//blockquote');
if (!is_null($blockquote_elements)) {
foreach ($blockquote_elements as $element) {
$existing_classes = [];
$with_setting_classes = [];
if ($element
->getAttribute('class')) {
$existing_classes[] = $element
->getAttribute('class');
}
$with_setting_classes = array_unique(array_merge($existing_classes, $setting_classes), SORT_REGULAR);
$all_classes = implode(' ', $with_setting_classes);
$element
->setAttribute('class', $all_classes);
}
}
$result
->setProcessedText(Html::serialize($dom));
}
return $result;
}