public function FilterUrlToVideo::process in URL to Video Filter 8
Same name and namespace in other branches
- 2.0.x src/Plugin/Filter/FilterUrlToVideo.php \Drupal\url_to_video_filter\Plugin\Filter\FilterUrlToVideo::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/ FilterUrlToVideo.php, line 70
Class
- FilterUrlToVideo
- Provides a filter to convert various video sharing website URLs to links.
Namespace
Drupal\url_to_video_filter\Plugin\FilterCode
public function process($text, $langcode) {
$youtube_found = FALSE;
$vimeo_found = FALSE;
// Process YouTube URLs.
if ($this->settings['youtube']) {
$filter = $this->urlToVideoFilterService
->convertYouTubeUrls($text);
$text = $filter['text'];
$youtube_found = $filter['url_found'];
}
// Process Vimeo Urls.
if ($this->settings['vimeo']) {
$filter = $this->urlToVideoFilterService
->convertVimeoUrls($text);
$text = $filter['text'];
$vimeo_found = $filter['url_found'];
}
$libraries = [];
$result = new FilterProcessResult($text);
if ($youtube_found) {
$libraries[] = 'url_to_video_filter/youtube_embed';
}
if ($vimeo_found) {
$libraries[] = 'url_to_video_filter/vimeo_embed';
}
$js_settings['urlToVideoFilter'] = [];
if ($this->settings['youtube'] && $this->settings['youtube_webp_preview']) {
$js_settings['urlToVideoFilter']['youtubeWebp'] = TRUE;
}
if ($this->settings['autoload']) {
$js_settings['urlToVideoFilter']['autoload'] = TRUE;
}
$result
->setAttachments([
'drupalSettings' => $js_settings,
'library' => $libraries,
]);
return $result;
}