diff --git a/core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php b/core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php index 3e123a5bce..d72a62e6a8 100644 --- a/core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php +++ b/core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php @@ -18,6 +18,7 @@ use Drupal\Core\Form\SubformState; use Drupal\Core\Form\SubformStateInterface; use Drupal\Core\Language\LanguageManagerInterface; +use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\ckeditor5\SmartDefaultSettings; use Drupal\Core\Validation\Plugin\Validation\Constraint\PrimitiveTypeConstraint; @@ -263,8 +264,15 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta assert($editor->getSettings() === $this->getDefaultSettings()); if (!$format->isNew()) { [$editor, $messages] = $this->smartDefaultSettings->computeSmartDefaultSettings($editor, $format); - foreach ($messages as $message) { - $this->messenger()->addMessage($message); + foreach ($messages as $type => $messages_per_type) { + foreach ($messages_per_type as $message) { + $this->messenger()->addMessage($message, $type); + } + } + if (isset($messages[MessengerInterface::TYPE_WARNING]) || isset($messages[MessengerInterface::TYPE_ERROR])) { + $this->messenger()->addMessage($this->t('Check this handbook page for details about compatibility issues of contrib modules.', [ + ':handbook' => 'https://www.drupal.org/node/3273985', + ]), MessengerInterface::TYPE_WARNING); } } $eventual_editor_and_format = $this->getEventualEditorWithPrimedFilterFormat($form_state, $editor); diff --git a/core/modules/ckeditor5/src/SmartDefaultSettings.php b/core/modules/ckeditor5/src/SmartDefaultSettings.php index 636de082d0..442af4062b 100644 --- a/core/modules/ckeditor5/src/SmartDefaultSettings.php +++ b/core/modules/ckeditor5/src/SmartDefaultSettings.php @@ -12,6 +12,7 @@ use Drupal\ckeditor5\Plugin\CKEditor5PluginManagerInterface; use Drupal\Component\Assertion\Inspector; use Drupal\Component\Plugin\PluginManagerInterface; +use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\editor\EditorInterface; use Drupal\editor\Entity\Editor; @@ -141,27 +142,27 @@ public function computeSmartDefaultSettings(?EditorInterface $text_editor, Filte $unsupported = $missing->diff($missing_attributes); if ($enabling_message_content) { - $messages[] = $this->t('The following plugins were enabled to support tags that are allowed by this text format: %enabling_message_content.', + $messages[MessengerInterface::TYPE_STATUS][] = $this->t('The following plugins were enabled to support tags that are allowed by this text format: %enabling_message_content.', ['%enabling_message_content' => $enabling_message_content], ); } // Warn user about unsupported tags. if (!$unsupported->isEmpty()) { $this->addTagsToSourceEditing($editor, $unsupported); - $messages[] = $this->t("The following tags were permitted by this format's filter configuration, but no plugin was available that supports them. To ensure the tags remain supported by this text format, the following were added to the Source Editing plugin's Manually editable HTML tags: @unsupported_string.", [ + $messages[MessengerInterface::TYPE_STATUS][] = $this->t("The following tags were permitted by this format's filter configuration, but no plugin was available that supports them. To ensure the tags remain supported by this text format, the following were added to the Source Editing plugin's Manually editable HTML tags: @unsupported_string.", [ '@unsupported_string' => $unsupported->toFilterHtmlAllowedTagsString(), ]); } if ($enabled_for_attributes_message_content) { - $messages[] = $this->t('The following plugins were enabled to support specific attributes that are allowed by this text format: %enabled_for_attributes_message_content.', + $messages[MessengerInterface::TYPE_STATUS][] = $this->t('The following plugins were enabled to support specific attributes that are allowed by this text format: %enabled_for_attributes_message_content.', ['%enabled_for_attributes_message_content' => $enabled_for_attributes_message_content], ); } // Warn user about supported tags but missing attributes. if (!$missing_attributes->isEmpty()) { $this->addTagsToSourceEditing($editor, $missing_attributes); - $messages[] = $this->t("This format's HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin's Manually editable HTML tags: @missing_attributes.", [ + $messages[MessengerInterface::TYPE_STATUS][] = $this->t("This format's HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin's Manually editable HTML tags: @missing_attributes.", [ '@missing_attributes' => $missing_attributes->toFilterHtmlAllowedTagsString(), ]); } @@ -181,7 +182,7 @@ private function addTagsToSourceEditing(EditorInterface $editor, HTMLRestriction $messages = []; $settings = $editor->getSettings(); if (!isset($settings['toolbar']['items']) || !in_array('sourceEditing', $settings['toolbar']['items'])) { - $messages[] = $this->t('The Source Editing plugin was enabled to support tags and/or attributes that are not explicitly supported by any available CKEditor 5 plugins.'); + $messages[MessengerInterface::TYPE_STATUS][] = $this->t('The Source Editing plugin was enabled to support tags and/or attributes that are not explicitly supported by any available CKEditor 5 plugins.'); $settings['toolbar']['items'][] = 'sourceEditing'; } $allowed_tags_array = $settings['plugins']['ckeditor5_sourceEditing']['allowed_tags'] ?? []; @@ -232,7 +233,7 @@ private function createSettingsFromCKEditor4(array $ckeditor4_settings, array $e $equivalent = $this->upgradePluginManager->mapCKEditor4ToolbarButtonToCKEditor5ToolbarItem($cke4_button, $text_format_html_restrictions); } catch (\OutOfBoundsException $e) { - $messages[] = $this->t('The CKEditor 4 button %button does not have a known upgrade path. If it allowed editing markup, then you can do so now through the Source Editing functionality.', [ + $messages[MessengerInterface::TYPE_WARNING][] = $this->t('The CKEditor 4 button %button does not have a known upgrade path. If it allowed editing markup, then you can do so now through the Source Editing functionality.', [ '%button' => $cke4_button, ]); continue; @@ -270,7 +271,7 @@ private function createSettingsFromCKEditor4(array $ckeditor4_settings, array $e $settings['plugins'] += $cke5_plugin_settings; } catch (\OutOfBoundsException $e) { - $messages[] = $this->t('The %cke4_plugin_id plugin settings do not have a known upgrade path.', [ + $messages[MessengerInterface::TYPE_ERROR][] = $this->t('The %cke4_plugin_id plugin settings do not have a known upgrade path.', [ '%cke4_plugin_id' => $cke4_plugin_id, ]); continue; @@ -762,7 +763,7 @@ private function computeSubsetSettingForEnabledPluginsWithSubsets(EditorInterfac $subset_configuration = $this->upgradePluginManager->computeCKEditor5PluginSubsetConfiguration($plugin_name, $text_format); } catch (\OutOfBoundsException $e) { - $messages[] = $this->t('The CKEditor 5 plugin %button has a configurable subset of elements, but does not have a known upgrade path to configure that subset to match your text format. Hence it is now using its default configuration.', [ + $messages[MessengerInterface::TYPE_WARNING][] = $this->t('The CKEditor 5 plugin %button has a configurable subset of elements, but does not have a known upgrade path to configure that subset to match your text format. Hence it is now using its default configuration.', [ '%plugin' => $plugin_name, ]); continue; diff --git a/core/modules/ckeditor5/tests/src/Kernel/SmartDefaultSettingsTest.php b/core/modules/ckeditor5/tests/src/Kernel/SmartDefaultSettingsTest.php index 01579bb992..63fb8c9a7f 100644 --- a/core/modules/ckeditor5/tests/src/Kernel/SmartDefaultSettingsTest.php +++ b/core/modules/ckeditor5/tests/src/Kernel/SmartDefaultSettingsTest.php @@ -380,9 +380,13 @@ public function test(string $format_id, array $filters_to_drop, array $expected_ // The resulting pair should be valid. $this->assertSame([], $this->validatePairToViolationsArray($updated_text_editor, $updated_text_format, TRUE)); - foreach ($messages as $key => $message) { - $messages[$key] = (string) $message; + // Transforms TranslatableMarkup objects to string. + foreach ($messages as $type => $messages_per_type) { + foreach ($messages_per_type as $key => $message) { + $messages[$type][$key] = (string) $message; + } } + $this->assertSame($expected_messages, $messages); } @@ -460,8 +464,10 @@ public function provider() { 'expected_superset' => '', 'expected_fundamental_compatibility_violations' => [], 'expected_messages' => [ - 'The following plugins were enabled to support tags that are allowed by this text format: Code (for tags: <code>) Language (for tags: <span>).', - 'The following tags were permitted by this format\'s filter configuration, but no plugin was available that supports them. To ensure the tags remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <cite> <dl> <dt> <dd>.', + 'status' => [ + 'The following plugins were enabled to support tags that are allowed by this text format: Code (for tags: <code>) Language (for tags: <span>).', + 'The following tags were permitted by this format\'s filter configuration, but no plugin was available that supports them. To ensure the tags remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <cite> <dl> <dt> <dd>.', + ], ], ]; @@ -469,7 +475,9 @@ public function provider() { $basic_html_test_case, [ 'expected_messages' => [ - 'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>.', + 'status' => [ + 'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>.', + ], ], ] ); @@ -490,7 +498,9 @@ public function provider() { ], ], 'expected_messages' => [ - 'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img data-caption>.', + 'status' => [ + 'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img data-caption>.', + ], ], ]); @@ -510,7 +520,9 @@ public function provider() { ], ], 'expected_messages' => [ - 'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img data-align>.', + 'status' => [ + 'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img data-align>.', + ], ], ]); @@ -539,10 +551,11 @@ public function provider() { ], 'expected_superset' => $basic_html_test_case['expected_superset'], 'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'], - 'expected_messages' => array_merge( - $basic_html_test_case['expected_messages'], - ['This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h5 id>.'], - ), + 'expected_messages' => array_merge_recursive($basic_html_test_case['expected_messages'], [ + 'status' => [ + 'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h5 id>.', + ], + ]), ]; yield "basic_html_with_h1 can be switched to CKEditor 5 without problems, heading configuration computed automatically" => [ @@ -570,10 +583,11 @@ public function provider() { ], 'expected_superset' => $basic_html_test_case['expected_superset'], 'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'], - 'expected_messages' => array_merge( - $basic_html_test_case['expected_messages'], - ['This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>.'], - ), + 'expected_messages' => array_merge_recursive($basic_html_test_case['expected_messages'], [ + 'status' => [ + 'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>.', + ], + ]), ]; yield "basic_html_without_headings can be switched to CKEditor 5 without problems, heading configuration computed automatically" => [ @@ -599,10 +613,11 @@ public function provider() { ], 'expected_superset' => $basic_html_test_case['expected_superset'], 'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'], - 'expected_messages' => array_merge( - $basic_html_test_case['expected_messages'], - ['This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <a hreflang> <blockquote cite> <ul type> <ol start type>.'], - ), + 'expected_messages' => array_merge_recursive($basic_html_test_case['expected_messages'], [ + 'status' => [ + 'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <a hreflang> <blockquote cite> <ul type> <ol start type>.', + ], + ]), ]; yield "basic_html_with_pre can be switched to CKEditor 5 without problems, heading configuration computed automatically" => [ @@ -620,9 +635,11 @@ public function provider() { 'expected_superset' => ' ' . $basic_html_test_case['expected_superset'], 'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'], 'expected_messages' => [ - 'The following plugins were enabled to support tags that are allowed by this text format: Code (for tags: <code>) Language (for tags: <span>) Code Block (for tags: <pre>).', - $basic_html_test_case['expected_messages'][1], - 'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>.', + 'status' => [ + 'The following plugins were enabled to support tags that are allowed by this text format: Code (for tags: <code>) Language (for tags: <span>) Code Block (for tags: <pre>).', + $basic_html_test_case['expected_messages']['status'][1], + 'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>.', + ], ], ]; @@ -658,12 +675,12 @@ public function provider() { $basic_html_test_case['expected_superset'], ]), 'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'], - 'expected_messages' => array_merge($basic_html_test_case['expected_messages'], - - [ + 'expected_messages' => array_merge_recursive($basic_html_test_case['expected_messages'], [ + 'status' => [ 'The following plugins were enabled to support specific attributes that are allowed by this text format: Align center ( for tag: <p> to support: class with value(s): text-align-center), Justify ( for tag: <p> to support: class with value(s): text-align-justify).', 'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>.', - ]), + ], + ]), ]; yield "basic_html with media_embed added => needed => supported through sourceEditing (3 upgrade messages)" => [ @@ -681,8 +698,10 @@ public function provider() { ], 'expected_superset' => $basic_html_test_case['expected_superset'], 'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'], - 'expected_messages' => array_merge($basic_html_test_case['expected_messages'], [ - "This format's HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin's Manually editable HTML tags: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>.", + 'expected_messages' => array_merge_recursive($basic_html_test_case['expected_messages'], [ + 'status' => [ + "This format's HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin's Manually editable HTML tags: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>.", + ], ]), ]; @@ -702,10 +721,11 @@ public function provider() { ], 'expected_superset' => $basic_html_test_case['expected_superset'], 'expected_fundamental_compatibility_violations' => $basic_html_test_case['expected_fundamental_compatibility_violations'], - 'expected_messages' => array_merge($basic_html_test_case['expected_messages'], - [ + 'expected_messages' => array_merge_recursive($basic_html_test_case['expected_messages'], [ + 'status' => [ 'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img data-*>.', - ]), + ], + ]), ]; yield "restricted_html can be switched to CKEditor 5 after dropping the two markup-creating filters (3 upgrade messages)" => [ @@ -768,9 +788,14 @@ public function provider() { '' => 'CKEditor 5 needs at least the <p> and <br> tags to be allowed to be able to function. They are not allowed by the "Limit allowed HTML tags and correct faulty HTML" (filter_html) filter.', ], 'expected_messages' => [ - 'The following plugins were enabled to support tags that are allowed by this text format: Link (for tags: <a>) Block quote (for tags: <blockquote>) Code (for tags: <code>) List (for tags: <ul><ol><li>).', - 'The following tags were permitted by this format\'s filter configuration, but no plugin was available that supports them. To ensure the tags remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <cite> <dl> <dt> <dd>.', - 'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>.', + 'status' => [ + 'The following plugins were enabled to support tags that are allowed by this text format: Link (for tags: <a>) Block quote (for tags: <blockquote>) Code (for tags: <code>) List (for tags: <ul><ol><li>).', + 'The following tags were permitted by this format\'s filter configuration, but no plugin was available that supports them. To ensure the tags remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <cite> <dl> <dt> <dd>.', + 'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <a hreflang> <blockquote cite> <ul type> <ol start type> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>.', + ], + ], + 'expected_post_filter_drop_fundamental_compatibility_violations' => [ + '' => 'CKEditor 5 needs at least the <p> and <br> tags to be allowed to be able to function. They are not allowed by the "Limit allowed HTML tags and correct faulty HTML" (filter_html) filter.', ], ]; @@ -880,9 +905,11 @@ public function provider() { '' => 'CKEditor 5 needs at least the <p> and <br> tags to be allowed to be able to function. They are not allowed by the "Limit allowed HTML tags and correct faulty HTML" (filter_html) filter.', ], 'expected_messages' => [ - 'The following plugins were enabled to support tags that are allowed by this text format: Link (for tags: <a>) Block quote (for tags: <blockquote>) Code (for tags: <code>) List (for tags: <ul><ol><li>).', - 'The following tags were permitted by this format\'s filter configuration, but no plugin was available that supports them. To ensure the tags remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <cite> <dl> <dt> <dd>.', - 'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <a hreflang> <blockquote cite> <ul type> <ol start type="1 A I"> <h2 id="jump-*"> <h3 id> <h4 id> <h5 id> <h6 id>.', + 'status' => [ + 'The following plugins were enabled to support tags that are allowed by this text format: Link (for tags: <a>) Block quote (for tags: <blockquote>) Code (for tags: <code>) List (for tags: <ul><ol><li>).', + 'The following tags were permitted by this format\'s filter configuration, but no plugin was available that supports them. To ensure the tags remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <cite> <dl> <dt> <dd>.', + 'This format\'s HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported by this text format, the following were added to the Source Editing plugin\'s Manually editable HTML tags: <a hreflang> <blockquote cite> <ul type> <ol start type="1 A I"> <h2 id="jump-*"> <h3 id> <h4 id> <h5 id> <h6 id>.', + ], ], ]; @@ -904,8 +931,12 @@ public function provider() { 'expected_superset' => '', 'expected_fundamental_compatibility_violations' => [], 'expected_messages' => [ - 'The CKEditor 4 button Llama does not have a known upgrade path. If it allowed editing markup, then you can do so now through the Source Editing functionality.', - 'The llama_contextual_and_button plugin settings do not have a known upgrade path.', + 'warning' => [ + 'The CKEditor 4 button Llama does not have a known upgrade path. If it allowed editing markup, then you can do so now through the Source Editing functionality.', + ], + 'error' => [ + 'The llama_contextual_and_button plugin settings do not have a known upgrade path.', + ], ], ];