protected function VideoEmbedWysiwyg::getValidMatches in Video Embed Field 8
Same name and namespace in other branches
- 8.2 modules/video_embed_wysiwyg/src/Plugin/Filter/VideoEmbedWysiwyg.php \Drupal\video_embed_wysiwyg\Plugin\Filter\VideoEmbedWysiwyg::getValidMatches()
Get all valid matches in the WYSIWYG.
Parameters
string $text: The text to check for WYSIWYG matches.
Return value
array An array of data from the text keyed by the text content.
1 call to VideoEmbedWysiwyg::getValidMatches()
- VideoEmbedWysiwyg::process in modules/
video_embed_wysiwyg/ src/ Plugin/ Filter/ VideoEmbedWysiwyg.php - Performs the filter processing.
File
- modules/
video_embed_wysiwyg/ src/ Plugin/ Filter/ VideoEmbedWysiwyg.php, line 131
Class
- VideoEmbedWysiwyg
- The filter to turn tokens inserted into the WYSIWYG into videos.
Namespace
Drupal\video_embed_wysiwyg\Plugin\FilterCode
protected function getValidMatches($text) {
// Use a look ahead to match the capture groups in any order.
if (!preg_match_all('/(<p>)?(?<json>{(?=.*preview_thumbnail\\b)(?=.*settings\\b)(?=.*video_url\\b)(?=.*settings_summary)(.*)})(<\\/p>)?/', $text, $matches)) {
return [];
}
$valid_matches = [];
foreach ($matches['json'] as $delta => $match) {
// Ensure the JSON string is valid.
$embed_data = json_decode($match, TRUE);
if (!$embed_data || !is_array($embed_data)) {
continue;
}
if ($this
->isValidSettings($embed_data['settings'])) {
$valid_matches[$matches[0][$delta]] = $embed_data;
}
}
return $valid_matches;
}