From 0becafafbc23d3b0b97c8fe8392d2908b9ce9281 Mon Sep 17 00:00:00 2001 From: catch Date: Mon, 11 Jul 2022 12:24:52 +0900 Subject: [PATCH] Issue #3271094 by Wim Leers, lauriii, xjm, catch: Move Media CKEditor 4 integration into CKEditor --- core/.stylelintrc.json | 2 +- core/modules/ckeditor/ckeditor.libraries.yml | 7 + .../drupalmedia/ckeditor.drupalmedia.css | 0 .../js/ckeditor.drupalmedia.theme.es6.js | 17 ++ .../ckeditor/js/ckeditor.drupalmedia.theme.js | 10 + .../js/plugins/drupalmedia/plugin.es6.js | 0 .../js/plugins/drupalmedia/plugin.js | 0 .../src/Plugin/CKEditorPlugin/DrupalMedia.php | 10 +- .../src/FunctionalJavascript/MediaTest.php} | 8 +- .../modules/ckeditor5/ckeditor5.libraries.yml | 2 +- .../ckeditor5/ckeditor5.libraries.yml.orig | 188 ++++++++++++++++++ .../js/media_embed_ckeditor5.theme.es6.js | 19 -- .../js/media_embed_ckeditor5.theme.js | 10 - .../js/media_embed_ckeditor.theme.es6.js | 13 +- .../media/js/media_embed_ckeditor.theme.js | 2 - core/modules/media/media.libraries.yml | 2 + core/modules/media/media.module | 6 +- .../media/src/Form/EditorMediaDialog.php | 1 - .../media_test_embed.info.yml | 4 +- .../media_test_embed/media_test_embed.module | 3 +- .../Controller/TestMediaFilterController.php | 2 +- .../tests/src/Kernel/MediaEmbedFilterTest.php | 2 - 22 files changed, 245 insertions(+), 63 deletions(-) rename core/modules/{media => ckeditor}/css/plugins/drupalmedia/ckeditor.drupalmedia.css (100%) create mode 100644 core/modules/ckeditor/js/ckeditor.drupalmedia.theme.es6.js create mode 100644 core/modules/ckeditor/js/ckeditor.drupalmedia.theme.js rename core/modules/{media => ckeditor}/js/plugins/drupalmedia/plugin.es6.js (100%) rename core/modules/{media => ckeditor}/js/plugins/drupalmedia/plugin.js (100%) rename core/modules/{media => ckeditor}/src/Plugin/CKEditorPlugin/DrupalMedia.php (88%) rename core/modules/{media/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php => ckeditor/tests/src/FunctionalJavascript/MediaTest.php} (99%) create mode 100644 core/modules/ckeditor5/ckeditor5.libraries.yml.orig delete mode 100644 core/modules/ckeditor5/js/media_embed_ckeditor5.theme.es6.js delete mode 100644 core/modules/ckeditor5/js/media_embed_ckeditor5.theme.js diff --git a/core/.stylelintrc.json b/core/.stylelintrc.json index 1de82b94955..1c5887df5fb 100644 --- a/core/.stylelintrc.json +++ b/core/.stylelintrc.json @@ -477,7 +477,7 @@ "ignoreFiles": [ "assets/vendor/**/*.css", "tests/Drupal/Tests/Core/Asset/css_test_files/**/*.css", - "modules/media/css/plugins/drupalmedia/ckeditor.drupalmedia.css", + "modules/ckeditor/css/plugins/drupalmedia/ckeditor.drupalmedia.css", "themes/stable/css/core/assets/vendor/**/*.css", "themes/stable9/css/core/assets/vendor/**/*.css", "themes/stable9/css/media/plugins/drupalmedia/ckeditor.drupalmedia.css" diff --git a/core/modules/ckeditor/ckeditor.libraries.yml b/core/modules/ckeditor/ckeditor.libraries.yml index 7c6fc2f933b..f71b90c611d 100644 --- a/core/modules/ckeditor/ckeditor.libraries.yml +++ b/core/modules/ckeditor/ckeditor.libraries.yml @@ -90,3 +90,10 @@ drupal.ckeditor.language.admin: - core/jquery - core/drupal - core/drupal.vertical-tabs + +drupal.ckeditor.plugins.drupalmedia: + version: VERSION + js: + js/ckeditor.drupalmedia.theme.js: {} + dependencies: + - core/drupal diff --git a/core/modules/media/css/plugins/drupalmedia/ckeditor.drupalmedia.css b/core/modules/ckeditor/css/plugins/drupalmedia/ckeditor.drupalmedia.css similarity index 100% rename from core/modules/media/css/plugins/drupalmedia/ckeditor.drupalmedia.css rename to core/modules/ckeditor/css/plugins/drupalmedia/ckeditor.drupalmedia.css diff --git a/core/modules/ckeditor/js/ckeditor.drupalmedia.theme.es6.js b/core/modules/ckeditor/js/ckeditor.drupalmedia.theme.es6.js new file mode 100644 index 00000000000..fbc93079c2a --- /dev/null +++ b/core/modules/ckeditor/js/ckeditor.drupalmedia.theme.es6.js @@ -0,0 +1,17 @@ +/** + * @file + * Theme elements for the Media Embed CKEditor plugin. + */ + +((Drupal) => { + /** + * Themes the edit button for a media embed. + * + * @return {string} + * An HTML string to insert in the CKEditor. + */ + Drupal.theme.mediaEmbedEditButton = () => + ``; +})(Drupal); diff --git a/core/modules/ckeditor/js/ckeditor.drupalmedia.theme.js b/core/modules/ckeditor/js/ckeditor.drupalmedia.theme.js new file mode 100644 index 00000000000..629422479f0 --- /dev/null +++ b/core/modules/ckeditor/js/ckeditor.drupalmedia.theme.js @@ -0,0 +1,10 @@ +/** +* DO NOT EDIT THIS FILE. +* See the following change record for more information, +* https://www.drupal.org/node/2815083 +* @preserve +**/ + +(Drupal => { + Drupal.theme.mediaEmbedEditButton = () => ``; +})(Drupal); \ No newline at end of file diff --git a/core/modules/media/js/plugins/drupalmedia/plugin.es6.js b/core/modules/ckeditor/js/plugins/drupalmedia/plugin.es6.js similarity index 100% rename from core/modules/media/js/plugins/drupalmedia/plugin.es6.js rename to core/modules/ckeditor/js/plugins/drupalmedia/plugin.es6.js diff --git a/core/modules/media/js/plugins/drupalmedia/plugin.js b/core/modules/ckeditor/js/plugins/drupalmedia/plugin.js similarity index 100% rename from core/modules/media/js/plugins/drupalmedia/plugin.js rename to core/modules/ckeditor/js/plugins/drupalmedia/plugin.js diff --git a/core/modules/media/src/Plugin/CKEditorPlugin/DrupalMedia.php b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/DrupalMedia.php similarity index 88% rename from core/modules/media/src/Plugin/CKEditorPlugin/DrupalMedia.php rename to core/modules/ckeditor/src/Plugin/CKEditorPlugin/DrupalMedia.php index d475f1ab9c7..9365b096dcd 100644 --- a/core/modules/media/src/Plugin/CKEditorPlugin/DrupalMedia.php +++ b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/DrupalMedia.php @@ -1,6 +1,6 @@ moduleExtensionList->getPath('media') . '/js/plugins/drupalmedia/plugin.js'; + return $this->moduleExtensionList->getPath('ckeditor') . '/js/plugins/drupalmedia/plugin.js'; } /** @@ -124,7 +128,7 @@ class DrupalMedia extends PluginBase implements ContainerFactoryPluginInterface, */ public function getCssFiles(Editor $editor) { return [ - $this->moduleExtensionList->getPath('media') . '/css/plugins/drupalmedia/ckeditor.drupalmedia.css', + $this->moduleExtensionList->getPath('ckeditor') . '/css/plugins/drupalmedia/ckeditor.drupalmedia.css', $this->moduleExtensionList->getPath('system') . '/css/components/hidden.module.css', ]; } diff --git a/core/modules/media/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php b/core/modules/ckeditor/tests/src/FunctionalJavascript/MediaTest.php similarity index 99% rename from core/modules/media/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php rename to core/modules/ckeditor/tests/src/FunctionalJavascript/MediaTest.php index 53427a31012..e68edebd81c 100644 --- a/core/modules/media/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php +++ b/core/modules/ckeditor/tests/src/FunctionalJavascript/MediaTest.php @@ -1,6 +1,6 @@ { - /** - * Themes the error displayed when the media embed preview fails. - * - * @return {string} - * A string representing a DOM fragment. - * - * @see media-embed-error.html.twig - */ - Drupal.theme.mediaEmbedPreviewError = () => - `
${Drupal.t( - 'An error occurred while trying to preview the media. Please save your work and reload this page.', - )}
`; -})(Drupal); diff --git a/core/modules/ckeditor5/js/media_embed_ckeditor5.theme.js b/core/modules/ckeditor5/js/media_embed_ckeditor5.theme.js deleted file mode 100644 index bcacbb8bb5b..00000000000 --- a/core/modules/ckeditor5/js/media_embed_ckeditor5.theme.js +++ /dev/null @@ -1,10 +0,0 @@ -/** -* DO NOT EDIT THIS FILE. -* See the following change record for more information, -* https://www.drupal.org/node/2815083 -* @preserve -**/ - -(Drupal => { - Drupal.theme.mediaEmbedPreviewError = () => `
${Drupal.t('An error occurred while trying to preview the media. Please save your work and reload this page.')}
`; -})(Drupal); \ No newline at end of file diff --git a/core/modules/media/js/media_embed_ckeditor.theme.es6.js b/core/modules/media/js/media_embed_ckeditor.theme.es6.js index 52ef82aa7d7..bb2bd6dcda4 100644 --- a/core/modules/media/js/media_embed_ckeditor.theme.es6.js +++ b/core/modules/media/js/media_embed_ckeditor.theme.es6.js @@ -1,6 +1,6 @@ /** * @file - * Theme elements for the Media Embed CKEditor plugin. + * Theme elements for the Media Embed text editor plugins. */ ((Drupal) => { @@ -16,15 +16,4 @@ `
${Drupal.t( 'An error occurred while trying to preview the media. Please save your work and reload this page.', )}
`; - - /** - * Themes the edit button for a media embed. - * - * @return {string} - * An HTML string to insert in the CKEditor. - */ - Drupal.theme.mediaEmbedEditButton = () => - ``; })(Drupal); diff --git a/core/modules/media/js/media_embed_ckeditor.theme.js b/core/modules/media/js/media_embed_ckeditor.theme.js index 7a63f1120ff..bcacbb8bb5b 100644 --- a/core/modules/media/js/media_embed_ckeditor.theme.js +++ b/core/modules/media/js/media_embed_ckeditor.theme.js @@ -7,6 +7,4 @@ (Drupal => { Drupal.theme.mediaEmbedPreviewError = () => `
${Drupal.t('An error occurred while trying to preview the media. Please save your work and reload this page.')}
`; - - Drupal.theme.mediaEmbedEditButton = () => ``; })(Drupal); \ No newline at end of file diff --git a/core/modules/media/media.libraries.yml b/core/modules/media/media.libraries.yml index efc9dd1ada2..f8febc4dfcb 100644 --- a/core/modules/media/media.libraries.yml +++ b/core/modules/media/media.libraries.yml @@ -32,6 +32,8 @@ filter.caption: dependencies: - filter/caption +# Despite the name, this is actually not specific to CKEditor 4, and can be +# used by all text editor plugins. media_embed_ckeditor_theme: version: VERSION js: diff --git a/core/modules/media/media.module b/core/modules/media/media.module index b4d3112e9c6..30b219e5791 100644 --- a/core/modules/media/media.module +++ b/core/modules/media/media.module @@ -510,9 +510,9 @@ function media_filter_format_edit_form_validate($form, FormStateInterface $form_ * Implements hook_field_widget_single_element_form_alter(). */ function media_field_widget_single_element_form_alter(&$element, FormStateInterface $form_state, $context) { - // Add an attribute so that "drupalmedia" CKEditor plugin can pass the host - // entity's language to EditorMediaDialog, allowing it to present entities - // in the same language. + // Add an attribute so that text editors plugins can pass the host entity's + // language to EditorMediaDialog, allowing it to present entities in the same + // language. if (!empty($element['#type']) && $element['#type'] == 'text_format') { $element['#attributes']['data-media-embed-host-entity-langcode'] = $context['items']->getLangcode(); } diff --git a/core/modules/media/src/Form/EditorMediaDialog.php b/core/modules/media/src/Form/EditorMediaDialog.php index 65f2d598650..8a961df6d23 100644 --- a/core/modules/media/src/Form/EditorMediaDialog.php +++ b/core/modules/media/src/Form/EditorMediaDialog.php @@ -96,7 +96,6 @@ class EditorMediaDialog extends FormBase { $editor_object = $form_state->getUserInput()['editor_object']; // The data that the text editor sends to any dialog is in // the 'editor_object' key. - // @see core/modules/ckeditor/js/ckeditor.es6.js $media_embed_element = $editor_object['attributes']; $form_state->set('media_embed_element', $media_embed_element); $has_caption = $editor_object['hasCaption']; diff --git a/core/modules/media/tests/modules/media_test_embed/media_test_embed.info.yml b/core/modules/media/tests/modules/media_test_embed/media_test_embed.info.yml index a06c93a9275..eb7ca882743 100644 --- a/core/modules/media/tests/modules/media_test_embed/media_test_embed.info.yml +++ b/core/modules/media/tests/modules/media_test_embed/media_test_embed.info.yml @@ -1,5 +1,5 @@ -name: Media Embed plugin test -description: 'Provides functionality to test embedding media items in CKEditor.' +name: Media Embed text editor plugin test +description: 'Provides functionality to test embedding media items in text editors.' type: module package: Testing version: VERSION diff --git a/core/modules/media/tests/modules/media_test_embed/media_test_embed.module b/core/modules/media/tests/modules/media_test_embed/media_test_embed.module index 2b8071ccf43..35add70f030 100644 --- a/core/modules/media/tests/modules/media_test_embed/media_test_embed.module +++ b/core/modules/media/tests/modules/media_test_embed/media_test_embed.module @@ -2,7 +2,7 @@ /** * @file - * Helper module for the Media Embed CKEditor plugin tests. + * Helper module for the Media Embed text editor plugin tests. */ use Drupal\Core\Access\AccessResult; @@ -14,7 +14,6 @@ use Drupal\Core\Session\AccountInterface; * Implements hook_entity_view_alter(). */ function media_test_embed_entity_view_alter(&$build, EntityInterface $entity, EntityViewDisplayInterface $display) { - // @see \Drupal\Tests\media\FunctionalJavascript\CKEditorIntegrationTest::testPreviewUsesDefaultThemeAndIsClientCacheable() $build['#attributes']['data-media-embed-test-active-theme'] = \Drupal::theme()->getActiveTheme()->getName(); $build['#attributes']['data-media-embed-test-view-mode'] = $display->getMode(); } diff --git a/core/modules/media/tests/modules/media_test_embed/src/Controller/TestMediaFilterController.php b/core/modules/media/tests/modules/media_test_embed/src/Controller/TestMediaFilterController.php index f1173450d4f..09b926dba48 100644 --- a/core/modules/media/tests/modules/media_test_embed/src/Controller/TestMediaFilterController.php +++ b/core/modules/media/tests/modules/media_test_embed/src/Controller/TestMediaFilterController.php @@ -8,7 +8,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** - * Controller to allow testing of error handling in drupalmedia plugin.js. + * Controller to allow testing of error handling of Media Embed in text editors. */ class TestMediaFilterController extends MediaFilterController { diff --git a/core/modules/media/tests/src/Kernel/MediaEmbedFilterTest.php b/core/modules/media/tests/src/Kernel/MediaEmbedFilterTest.php index 4483b89b3d4..e2b4b820ad8 100644 --- a/core/modules/media/tests/src/Kernel/MediaEmbedFilterTest.php +++ b/core/modules/media/tests/src/Kernel/MediaEmbedFilterTest.php @@ -356,8 +356,6 @@ class MediaEmbedFilterTest extends MediaEmbedFilterTestBase { /** * Tests that only tags are processed. - * - * @see \Drupal\Tests\media\FunctionalJavascript\CKEditorIntegrationTest::testOnlyDrupalMediaTagProcessed() */ public function testOnlyDrupalMediaTagProcessed() { $content = $this->createEmbedCode([