From 7888b61dd42b643ac80d5299d83fa5265b541da2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tuomas=20V=C3=A4limaa?= Date: Fri, 2 Sep 2022 15:29:49 +0300 Subject: [PATCH] httmll 5 support --- composer.json | 29 +++++++++++++++++++++++ src/Plugin/Filter/IframeCookieConsent.php | 5 ++-- 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 composer.json diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..b5aca45 --- /dev/null +++ b/composer.json @@ -0,0 +1,29 @@ +{ + "name": "tvalimaa/iframe_cookie_consent", + "description": "Adds Ckeditor plugin which converts Youtube iframe embeds to support cookie consent", + "type": "drupal-module", + "authors": [ + { + "name": "Tuomas Välimaa (tvalimaa)", + "role": "Maintainer" + } + ], + "homepage": "https://github.com/tvalimaa/iframe_cookie_consent", + "require": { + "masterminds/html5": "^2.7" + }, + "repositories": [ + { + "type": "package", + "package": { + "name": "masterminds/html5", + "version": "2.7.6", + "type": "drupal-library", + "dist": { + "url": "https://github.com/Masterminds/html5-php/archive/refs/tags/2.7.6.zip", + "type": "zip" + } + } + } + ] +} diff --git a/src/Plugin/Filter/IframeCookieConsent.php b/src/Plugin/Filter/IframeCookieConsent.php index be5b858..976b8a9 100644 --- a/src/Plugin/Filter/IframeCookieConsent.php +++ b/src/Plugin/Filter/IframeCookieConsent.php @@ -4,6 +4,7 @@ use Drupal\filter\FilterProcessResult; use Drupal\filter\Plugin\FilterBase; +use Masterminds\HTML5; /** * Provides a filter to help celebrate good times! @@ -26,9 +27,9 @@ public function process($text, $langcode) { // Get cookie consent category. $consent_cat = $config->get('cookieconsent_category') ?? 'marketing'; // Load Ckeditor content to DOMDocument. - $dom = new \DOMDocument(); + $html5 = new HTML5(); libxml_use_internal_errors(true); - @$dom->loadHTML(mb_convert_encoding($text, 'HTML-ENTITIES', 'UTF-8')); + $dom = $html5->loadHTML(mb_convert_encoding($text, 'HTML-ENTITIES', 'UTF-8')); // Youtube regex pattern. $regex_pattern = "/(youtube.com|youtu.be)\/(embed)?(\?v=)?(\S+)?/"; $match = NULL;