public function SoEmbedFilter::process in Simple oEmbed 8
Same name and namespace in other branches
- 8.2 src/Plugin/Filter/SoEmbedFilter.php \Drupal\soembed\Plugin\Filter\SoEmbedFilter::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
- src/
Plugin/ Filter/ SoEmbedFilter.php, line 31
Class
- SoEmbedFilter
- Plugin annotation @Filter( id = "filter_soembed", title = @Translation("Simple oEmbed filter"), description = @Translation("Embeds media for URL that supports oEmbed standard."), settings = { "soembed_maxwidth" = 500, …
Namespace
Drupal\soembed\Plugin\FilterCode
public function process($text, $langcode) {
$lines = explode("\n", $text);
if (!empty($this->settings['soembed_replace_inline'])) {
// Match in-line urls. (First () in pattern is needed because the callback
// expects the url in the second pair of parentheses).
$lines = preg_replace_callback('#()(https?://[^\\s<]+)#', [
$this,
'embed',
], $lines);
}
else {
$lines = preg_replace_callback('#^(<p>)?(https?://\\S+?)(</p>)?$#', [
$this,
'embed',
], $lines);
}
$text = implode("\n", $lines);
return new FilterProcessResult($text);
}