From eda47b52ea7f467f244fa289921d137c1a67d6fc Mon Sep 17 00:00:00 2001 From: Lee Rowlands <lee.rowlands@previousnext.com.au> Date: Sat, 11 Feb 2023 08:14:21 +1000 Subject: [PATCH] Issue #3339400 by gxleano, royalpinto007, VladimirAus, fjgarlin, longwave: Incorrect use of FormattableMarkup in logger messages (cherry picked from commit 9fbbf6e52ee0e3fcbf2a0f06d7b712afda96c593) --- .../ckeditor5/src/SmartDefaultSettings.php | 31 ++++++++++--------- .../src/Kernel/SmartDefaultSettingsTest.php | 5 ++- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/core/modules/ckeditor5/src/SmartDefaultSettings.php b/core/modules/ckeditor5/src/SmartDefaultSettings.php index a10a64b2133e..9da23d1aba1e 100644 --- a/core/modules/ckeditor5/src/SmartDefaultSettings.php +++ b/core/modules/ckeditor5/src/SmartDefaultSettings.php @@ -178,39 +178,40 @@ public function computeSmartDefaultSettings(?EditorInterface $text_editor, Filte $unsupported = $missing->diff($missing_attributes); if ($enabling_message_content) { - $this->logger->info(new FormattableMarkup('The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the %text_format text format: %enabling_message_content. The text format must be saved to make these changes active.', + $this->logger->info('The CKEditor 5 migration enabled the following plugins to support tags that are allowed by the %text_format text format: %enabling_message_content. The text format must be saved to make these changes active.', [ '%text_format' => $editor->getFilterFormat()->get('name'), '%enabling_message_content' => $enabling_message_content, - ], - )); + ] + ); } + // Warn user about unsupported tags. if (!$unsupported->allowsNothing()) { $this->addTagsToSourceEditing($editor, $unsupported); $source_editing_additions = $source_editing_additions->merge($unsupported); - $this->logger->info(new FormattableMarkup("The following tags were permitted by the %text_format text 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 <em>Manually editable HTML tags</em>: @unsupported_string. The text format must be saved to make these changes active.", [ + $this->logger->info("The following tags were permitted by the %text_format text 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 <em>Manually editable HTML tags</em>: @unsupported_string. The text format must be saved to make these changes active.", [ '%text_format' => $editor->getFilterFormat()->get('name'), '@unsupported_string' => $unsupported->toFilterHtmlAllowedTagsString(), - ])); + ]); } if ($enabled_for_attributes_message_content) { - $this->logger->info(new FormattableMarkup('The CKEditor 5 migration process enabled the following plugins to support specific attributes that are allowed by the %text_format text format: %enabled_for_attributes_message_content.', + $this->logger->info('The CKEditor 5 migration process enabled the following plugins to support specific attributes that are allowed by the %text_format text format: %enabled_for_attributes_message_content.', [ '%text_format' => $editor->getFilterFormat()->get('name'), '%enabled_for_attributes_message_content' => $enabled_for_attributes_message_content, ], - )); + ); } // Warn user about supported tags but missing attributes. if (!$missing_attributes->allowsNothing()) { $this->addTagsToSourceEditing($editor, $missing_attributes); $source_editing_additions = $source_editing_additions->merge($missing_attributes); - $this->logger->info(new FormattableMarkup("As part of migrating to CKEditor 5, it was found that the %text_format text format's HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported, the following were added to the Source Editing plugin's <em>Manually editable HTML tags</em>: @missing_attributes. The text format must be saved to make these changes active.", [ + $this->logger->info("As part of migrating to CKEditor 5, it was found that the %text_format text format's HTML filters includes plugins that support the following tags, but not some of their attributes. To ensure these attributes remain supported, the following were added to the Source Editing plugin's <em>Manually editable HTML tags</em>: @missing_attributes. The text format must be saved to make these changes active.", [ '%text_format' => $editor->getFilterFormat()->get('name'), '@missing_attributes' => $missing_attributes->toFilterHtmlAllowedTagsString(), - ])); + ]); } } @@ -225,10 +226,10 @@ public function computeSmartDefaultSettings(?EditorInterface $text_editor, Filte $missing_fundamental_tags = $fundamental->diff($filter_html_restrictions); if (!$missing_fundamental_tags->allowsNothing()) { $editor->getFilterFormat()->setFilterConfig('filter_html', $filter_html_restrictions->merge($fundamental)->getAllowedElements()); - $this->logger->warning(new FormattableMarkup("As part of migrating the %text_format text format to CKEditor 5, the following tag(s) were added to <em>Limit allowed HTML tags and correct faulty HTML</em>, because they are needed to provide fundamental CKEditor 5 functionality : @missing_tags. The text format must be saved to make these changes active.", [ + $this->logger->warning("As part of migrating the %text_format text format to CKEditor 5, the following tag(s) were added to <em>Limit allowed HTML tags and correct faulty HTML</em>, because they are needed to provide fundamental CKEditor 5 functionality : @missing_tags. The text format must be saved to make these changes active.", [ '%text_format' => $editor->getFilterFormat()->get('name'), '@missing_tags' => $missing_fundamental_tags->toFilterHtmlAllowedTagsString(), - ])); + ]); } } @@ -448,9 +449,9 @@ private function createSettingsFromCKEditor4(array $ckeditor4_settings, HTMLRest $equivalent = $this->upgradePluginManager->mapCKEditor4ToolbarButtonToCKEditor5ToolbarItem($cke4_button, $text_format_html_restrictions); } catch (\OutOfBoundsException $e) { - $this->logger->warning(new FormattableMarkup('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.', [ + $this->logger->warning('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, - ])); + ]); $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, ]); @@ -489,9 +490,9 @@ private function createSettingsFromCKEditor4(array $ckeditor4_settings, HTMLRest $settings['plugins'] += $cke5_plugin_settings; } catch (\OutOfBoundsException $e) { - $this->logger->warning(new FormattableMarkup('The %cke4_plugin_id plugin settings do not have a known upgrade path.', [ + $this->logger->warning('The %cke4_plugin_id plugin settings do not have a known upgrade path.', [ '%cke4_plugin_id' => $cke4_plugin_id, - ])); + ]); $messages[MessengerInterface::TYPE_WARNING][] = $this->t('The %cke4_plugin_id plugin settings do not have a known upgrade path.', [ '%cke4_plugin_id' => $cke4_plugin_id, ]); diff --git a/core/modules/ckeditor5/tests/src/Kernel/SmartDefaultSettingsTest.php b/core/modules/ckeditor5/tests/src/Kernel/SmartDefaultSettingsTest.php index 203131afb713..ac588ff9d6de 100644 --- a/core/modules/ckeditor5/tests/src/Kernel/SmartDefaultSettingsTest.php +++ b/core/modules/ckeditor5/tests/src/Kernel/SmartDefaultSettingsTest.php @@ -5,6 +5,7 @@ namespace Drupal\Tests\ckeditor5\Kernel; use Drupal\ckeditor5\HTMLRestrictions; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Entity\Entity\EntityViewMode; use Drupal\editor\Entity\Editor; @@ -576,7 +577,9 @@ public function test(string $format_id, array $filters_to_drop, array $expected_ ]; $db_logs = []; foreach ($db_logged as $log) { - $db_logs[$type_to_status[$log->severity]][] = $log->message; + $variables = unserialize($log->variables); + $message = new FormattableMarkup($log->message, $variables); + $db_logs[$type_to_status[$log->severity]][] = (string) $message; } // Transforms TranslatableMarkup objects to string. -- GitLab