diff --git a/core/modules/ckeditor/ckeditor.module b/core/modules/ckeditor/ckeditor.module index aa793aabf316bd2df540ae0ebd2e4f6a8b9b9fbc..eb646c953c5ee6b9301dc09d1cae3226458f4081 100644 --- a/core/modules/ckeditor/ckeditor.module +++ b/core/modules/ckeditor/ckeditor.module @@ -49,6 +49,10 @@ function ckeditor_theme() { * Implements hook_ckeditor_css_alter(). */ function ckeditor_ckeditor_css_alter(array &$css, Editor $editor) { + if (!$editor->hasAssociatedFilterFormat()) { + return; + } + // Add the filter caption CSS if the text format associated with this text // editor uses the filter_caption filter. This is used by the included // CKEditor DrupalImageCaption plugin. diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/CKEditorPlugin/DrupalImageCaption.php b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/CKEditorPlugin/DrupalImageCaption.php index 0b753e8ae1b276287c51dadfad1c9a191f1786bf..5c2fffa5a40ff76ff6e94ba2976a191572d1e6f4 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/CKEditorPlugin/DrupalImageCaption.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/CKEditorPlugin/DrupalImageCaption.php @@ -68,6 +68,10 @@ public function getConfig(Editor $editor) { * {@inheritdoc} */ function isEnabled(Editor $editor) { + if (!$editor->hasAssociatedFilterFormat()) { + return FALSE; + } + // Automatically enable this plugin if the text format associated with this // text editor uses the filter_caption filter and the DrupalImage button is // enabled. diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/CKEditorPlugin/Internal.php b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/CKEditorPlugin/Internal.php index 78b725e5fb85dc8c1931a15827047e7952604c97..72723572951bd3acfbc777d3280cb91f54578472 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/CKEditorPlugin/Internal.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/CKEditorPlugin/Internal.php @@ -289,9 +289,16 @@ protected function generateFormatTagsSetting(Editor $editor) { * array or FALSE. The latter indicates that nothing is disallowed. */ protected function generateACFSettings(Editor $editor) { - // When nothing is disallowed, set allowedContent to true. + // When no text format is associated yet, assume nothing is disallowed, so + // set allowedContent to true. + if (!$editor->hasAssociatedFilterFormat()) { + return TRUE; + } + $format = $editor->getFilterFormat(); $filter_types = $format->getFilterTypes(); + + // When nothing is disallowed, set allowedContent to true. if (!in_array(FilterInterface::TYPE_HTML_RESTRICTOR, $filter_types)) { return array(TRUE, FALSE); } diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorAdminTest.php b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorAdminTest.php index 4680f9e3b120a1122d946eff7c182c86777fcbf4..0d2d5b2d5b0dd80c59847caa570b8c5e6dee9a41 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorAdminTest.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorAdminTest.php @@ -8,6 +8,7 @@ namespace Drupal\ckeditor\Tests; use Drupal\editor\Entity\Editor; +use Drupal\filter\FilterFormatInterface; use Drupal\simpletest\WebTestBase; /** @@ -46,7 +47,10 @@ function setUp() { $this->admin_user = $this->drupalCreateUser(array('administer filters')); } - function testAdmin() { + /** + * Tests configuring a text editor for an existing text format. + */ + function testExistingFormat() { $ckeditor = $this->container->get('plugin.manager.editor')->createInstance('ckeditor'); $this->drupalLogin($this->admin_user); @@ -187,4 +191,66 @@ function testAdmin() { $this->assertIdentical($expected_settings, $editor->getSettings()); } + /** + * Tests configuring a text editor for a new text format. + * + * This test only needs to ensure that the basics of the CKEditor + * configuration form work; details are tested in testExistingFormat(). + */ + function testNewFormat() { + $this->drupalLogin($this->admin_user); + $this->drupalGet('admin/config/content/formats/add'); + + // Verify the "Text Editor"