From 266679c66232b33cad6c70d4cbd5a8bf8455039d Mon Sep 17 00:00:00 2001
From: Lauri Eskola <lauri.eskola@acquia.com>
Date: Mon, 15 Nov 2021 13:22:22 +0200
Subject: [PATCH] Issue #3249263 by alexpott, andypost, Wim Leers: CKEditor 5
needs validate the filters in the correct order - CKEditor 5 tests fail
locally
(cherry picked from commit dc51481d8ac7c8eb95289f13a3e536ae00fd9a5a)
---
...mentalCompatibilityConstraintValidator.php | 30 ++++++-------
.../src/Kernel/SmartDefaultSettingsTest.php | 4 +-
.../tests/src/Kernel/ValidatorsTest.php | 43 +++++++++++++++++--
3 files changed, 54 insertions(+), 23 deletions(-)
diff --git a/core/modules/ckeditor5/src/Plugin/Validation/Constraint/FundamentalCompatibilityConstraintValidator.php b/core/modules/ckeditor5/src/Plugin/Validation/Constraint/FundamentalCompatibilityConstraintValidator.php
index 43de2c35c9a5..0913e8cccd21 100644
--- a/core/modules/ckeditor5/src/Plugin/Validation/Constraint/FundamentalCompatibilityConstraintValidator.php
+++ b/core/modules/ckeditor5/src/Plugin/Validation/Constraint/FundamentalCompatibilityConstraintValidator.php
@@ -84,13 +84,11 @@ private function checkNoMarkupFilters(FilterFormatInterface $text_format, Fundam
$text_format,
FilterInterface::TYPE_MARKUP_LANGUAGE
);
- if (!empty($markup_filters)) {
- foreach ($markup_filters as $markup_filter) {
- $this->context->buildViolation($constraint->noMarkupFiltersMessage)
- ->setParameter('%filter_label', $markup_filter->getLabel())
- ->setParameter('%filter_plugin_id', $markup_filter->getPluginId())
- ->addViolation();
- }
+ foreach ($markup_filters as $markup_filter) {
+ $this->context->buildViolation($constraint->noMarkupFiltersMessage)
+ ->setParameter('%filter_label', $markup_filter->getLabel())
+ ->setParameter('%filter_plugin_id', $markup_filter->getPluginId())
+ ->addViolation();
}
}
@@ -194,25 +192,21 @@ private function checkHtmlRestrictionsMatch(EditorInterface $text_editor, Fundam
* conditions to be met. Must return TRUE when it meets the conditions,
* FALSE otherwise.
*
- * @return \Drupal\filter\Plugin\FilterInterface[]
- * The matched filter plugins.
+ * @return iterable|\Drupal\filter\Plugin\FilterInterface[]
+ * An iterable of matched filter plugins.
*/
- private static function getFiltersInFormatOfType(FilterFormatInterface $text_format, int $filter_type, callable $extra_requirements = NULL): array {
+ private static function getFiltersInFormatOfType(FilterFormatInterface $text_format, int $filter_type, callable $extra_requirements = NULL): iterable {
assert(in_array($filter_type, [
FilterInterface::TYPE_MARKUP_LANGUAGE,
FilterInterface::TYPE_HTML_RESTRICTOR,
FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE,
]));
- return array_filter($text_format->filters()->getAll(), function (FilterInterface $filter) use ($filter_type, $extra_requirements) {
- if (!$filter->status) {
- return FALSE;
+ foreach ($text_format->filters() as $id => $filter) {
+ if ($filter->status && $filter->getType() === $filter_type && ($extra_requirements === NULL || $extra_requirements($filter))) {
+ yield $id => $filter;
}
- if ($filter->getType() === $filter_type && ($extra_requirements === NULL || $extra_requirements($filter))) {
- return TRUE;
- }
- return FALSE;
- });
+ }
}
/**
diff --git a/core/modules/ckeditor5/tests/src/Kernel/SmartDefaultSettingsTest.php b/core/modules/ckeditor5/tests/src/Kernel/SmartDefaultSettingsTest.php
index d03e2c98f968..addcc53a3d23 100644
--- a/core/modules/ckeditor5/tests/src/Kernel/SmartDefaultSettingsTest.php
+++ b/core/modules/ckeditor5/tests/src/Kernel/SmartDefaultSettingsTest.php
@@ -517,8 +517,8 @@ public function provider() {
'expected_superset' => '<br> <p>',
'expected_fundamental_compatibility_violations' => [
'' => [
- 0 => 'CKEditor 5 only works with HTML-based text formats. The "<em class="placeholder">Convert URLs into links</em>" (<em class="placeholder">filter_url</em>) filter implies this text format is not HTML anymore.',
- 1 => 'CKEditor 5 only works with HTML-based text formats. The "<em class="placeholder">Convert line breaks into HTML (i.e. <code>&lt;br&gt;</code> and <code>&lt;p&gt;</code>)</em>" (<em class="placeholder">filter_autop</em>) filter implies this text format is not HTML anymore.',
+ 0 => 'CKEditor 5 only works with HTML-based text formats. The "<em class="placeholder">Convert line breaks into HTML (i.e. <code>&lt;br&gt;</code> and <code>&lt;p&gt;</code>)</em>" (<em class="placeholder">filter_autop</em>) filter implies this text format is not HTML anymore.',
+ 1 => 'CKEditor 5 only works with HTML-based text formats. The "<em class="placeholder">Convert URLs into links</em>" (<em class="placeholder">filter_url</em>) filter implies this text format is not HTML anymore.',
],
],
'expected_messages' => [
diff --git a/core/modules/ckeditor5/tests/src/Kernel/ValidatorsTest.php b/core/modules/ckeditor5/tests/src/Kernel/ValidatorsTest.php
index 151cfbd9d8c5..2cb9442e70d3 100644
--- a/core/modules/ckeditor5/tests/src/Kernel/ValidatorsTest.php
+++ b/core/modules/ckeditor5/tests/src/Kernel/ValidatorsTest.php
@@ -416,7 +416,7 @@ public function providerPair(): array {
'id' => 'filter_url',
'provider' => 'filter',
'status' => TRUE,
- 'weight' => 0,
+ 'weight' => -10,
'settings' => [
'filter_url_length' => 72,
],
@@ -429,6 +429,43 @@ public function providerPair(): array {
],
],
];
+ $data['INVALID: non-HTML format: filter_autop + filter_url (different order)'] = [
+ 'settings' => [
+ 'toolbar' => [
+ 'items' => [
+ 'bold',
+ ],
+ ],
+ 'plugins' => [],
+ ],
+ 'image_upload' => [
+ 'status' => FALSE,
+ ],
+ 'filters' => [
+ 'filter_autop' => [
+ 'id' => 'filter_autop',
+ 'provider' => 'filter',
+ 'status' => TRUE,
+ 'weight' => 0,
+ 'settings' => [],
+ ],
+ 'filter_url' => [
+ 'id' => 'filter_url',
+ 'provider' => 'filter',
+ 'status' => TRUE,
+ 'weight' => 10,
+ 'settings' => [
+ 'filter_url_length' => 72,
+ ],
+ ],
+ ],
+ 'violations' => [
+ '' => [
+ 'CKEditor 5 only works with HTML-based text formats. The "<em class="placeholder">Convert line breaks into HTML (i.e. <code>&lt;br&gt;</code> and <code>&lt;p&gt;</code>)</em>" (<em class="placeholder">filter_autop</em>) filter implies this text format is not HTML anymore.',
+ 'CKEditor 5 only works with HTML-based text formats. The "<em class="placeholder">Convert URLs into links</em>" (<em class="placeholder">filter_url</em>) filter implies this text format is not HTML anymore.',
+ ],
+ ],
+ ];
$data['INVALID: forbidden tags'] = [
'settings' => [
'toolbar' => [
@@ -456,7 +493,7 @@ public function providerPair(): array {
'' => 'CKEditor 5 needs at least the <p> and <br> tags to be allowed to be able to function. They are forbidden by the "<em class="placeholder">Tag and attribute restricting filter</em>" (<em class="placeholder">filter_test_restrict_tags_and_attributes</em>) filter.',
],
];
- $restricted_html_format_filters = Yaml::parseFile('profiles/standard/config/install/filter.format.restricted_html.yml')['filters'];
+ $restricted_html_format_filters = Yaml::parseFile(__DIR__ . '/../../../../../profiles/standard/config/install/filter.format.restricted_html.yml')['filters'];
$data['INVALID: the default restricted_html text format'] = [
'settings' => [
'toolbar' => [
@@ -470,8 +507,8 @@ public function providerPair(): array {
'filters' => $restricted_html_format_filters,
'violations' => [
'' => [
- 'CKEditor 5 only works with HTML-based text formats. The "<em class="placeholder">Convert URLs into links</em>" (<em class="placeholder">filter_url</em>) filter implies this text format is not HTML anymore.',
'CKEditor 5 only works with HTML-based text formats. The "<em class="placeholder">Convert line breaks into HTML (i.e. <code>&lt;br&gt;</code> and <code>&lt;p&gt;</code>)</em>" (<em class="placeholder">filter_autop</em>) filter implies this text format is not HTML anymore.',
+ 'CKEditor 5 only works with HTML-based text formats. The "<em class="placeholder">Convert URLs into links</em>" (<em class="placeholder">filter_url</em>) filter implies this text format is not HTML anymore.',
],
],
];
--
GitLab