core/modules/ckeditor/ckeditor.module | 4 ++ .../Plugin/CKEditorPlugin/DrupalImageCaption.php | 4 ++ .../ckeditor/Plugin/CKEditorPlugin/Internal.php | 9 ++- .../Drupal/ckeditor/Tests/CKEditorAdminTest.php | 68 +++++++++++++++++++++- .../editor/lib/Drupal/editor/EditorInterface.php | 16 ++++- .../editor/lib/Drupal/editor/Entity/Editor.php | 7 +++ .../lib/Drupal/filter/FilterFormatInterface.php | 2 +- 7 files changed, 106 insertions(+), 4 deletions(-) diff --git a/core/modules/ckeditor/ckeditor.module b/core/modules/ckeditor/ckeditor.module index aa793aa..eb646c9 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 0b753e8..5c2fffa 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 78b725e..7272357 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 4680f9e..0d2d5b2 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"