diff -u b/core/modules/ckeditor/ckeditor.module b/core/modules/ckeditor/ckeditor.module --- b/core/modules/ckeditor/ckeditor.module +++ b/core/modules/ckeditor/ckeditor.module @@ -92,6 +92,19 @@ } /** + * Implements hook_page_build(). + */ +function ckeditor_page_build(&$page) { + // Add our CSS file that adds common needed classes, such as align-left, + // align-right, underline, indent, etc. + // @todo The CSS in this file needs to continue to be applied even after + // disabling ckeditor.module after CKEditor-edited content is saved, + // so move it to somewhere global, such as system.base.css: + // http://drupal.org/node/1904976. + $page['#attached']['library'][] = array('ckeditor', 'drupal.ckeditor.css'); +} + +/** * Retrieves the default theme's CKEditor stylesheets defined in the .info file. * * Themes may specify iframe-specific CSS files for use with CKEditor by diff -u b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/ckeditor/plugin/Internal.php b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/ckeditor/plugin/Internal.php --- b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/ckeditor/plugin/Internal.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/ckeditor/plugin/Internal.php @@ -45,6 +45,7 @@ public function getConfig(Editor $editor) { // Reasonable defaults that provide expected basic behavior. $config = array( + 'customConfig' => '', // Don't load CKEditor's config.js file. 'pasteFromWordPromptCleanup' => TRUE, 'indentClasses' => array('indent1', 'indent2', 'indent3'), 'justifyClasses' => array('align-left', 'align-center', 'align-right', 'align-justify'), diff -u b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorAdminTest.php b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorAdminTest.php --- b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorAdminTest.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorAdminTest.php @@ -68,31 +68,52 @@ $this->assertTrue(((string) $options[1]) === 'CKEditor', 'Option 2 in the Text Editor select is "CKEditor".'); $this->assertTrue(((string) $options[0]['selected']) === 'selected', 'Option 1 ("None") is selected.'); + // Ensure the CKEditor editor returns the expected default settings. + $expected_default_settings = array( + 'toolbar' => array( + 'buttons' => array( + array( + 'Bold', 'Italic', + '|', 'Link', 'Unlink', + '|', 'BulletedList', 'NumberedList', + '|', 'Blockquote', 'Image', + '|', 'Source', + ), + ), + ), + 'plugins' => array(), + ); + $this->assertIdentical($ckeditor->getDefaultSettings(), $expected_default_settings); + // Select the "CKEditor" editor and click the "Configure" button. $edit = array( 'editor[editor]' => 'ckeditor', ); - // $this->drupalPost(NULL, $edit, t('Configure')); $this->drupalPostAjax(NULL, $edit, 'editor_configure'); $editor = entity_load('editor', 'filtered_html'); $this->assertFalse($editor, 'No Editor config entity exists yet.'); - // Default configuration. - $default_buttons_value = '[["Source","|","Bold","Italic","|","NumberedList","BulletedList","Blockquote","|","JustifyLeft","JustifyCenter","JustifyRight","|","Link","Unlink","|","Image","Maximize"]]'; - $this->assertFieldByName('editor[settings][toolbar][buttons]', $default_buttons_value, 'Buttons configuration'); + // Ensure the toolbar buttons configuration value is initialized to the + // expected default value. + $expected_buttons_value = json_encode($expected_default_settings['toolbar']['buttons']); + $this->assertFieldByName('editor[settings][toolbar][buttons]', $expected_buttons_value); + + // Ensure the styles textarea exists and is initialized empty. $styles_textarea = $this->xpath('//textarea[@name="editor[settings][plugins][stylescombo][styles]"]'); $this->assertFieldByXPath('//textarea[@name="editor[settings][plugins][stylescombo][styles]"]', '', 'The styles textarea exists and is empty.'); $this->assertTrue(count($styles_textarea) === 1, 'The "styles" textarea exists.'); + + // Submit the form to save the selection of CKEditor as the chosen editor. $this->drupalPost(NULL, $edit, t('Save configuration')); // Ensure an Editor object exists now, with the proper settings. - $expected_settings = $ckeditor->getDefaultSettings(); + $expected_settings = $expected_default_settings; $expected_settings['plugins']['stylescombo']['styles'] = ''; $editor = entity_load('editor', 'filtered_html'); $this->assertTrue($editor instanceof Editor, 'An Editor config entity exists now.'); $this->assertIdentical($expected_settings, $editor->settings, 'The Editor config entity has the correct settings.'); - // Configure a plugin. + // Configure the Styles plugin, and ensure the updated settings are saved. $edit = array( 'editor[settings][plugins][stylescombo][styles]' => "Title|h1.title\nCallout|p.callout\n\n", ); @@ -102,15 +123,17 @@ $this->assertTrue($editor instanceof Editor, 'An Editor config entity exists.'); $this->assertIdentical($expected_settings, $editor->settings, 'The Editor config entity has the correct settings.'); - // "Drag and drop" buttons: remove one button, add a separator, add a button - // and finally, add a button to a new row. + // Change the buttons that appear on the toolbar (in JavaScript, this is + // done via drag and drop, but here we can only emulate the end result of + // that interaction). Test multiple toolbar rows and a divider within a row. + $expected_settings['toolbar']['buttons'] = array( + array('Undo', '|', 'Redo'), + array('JustifyCenter'), + ); $edit = array( - 'editor[settings][toolbar][buttons]' => '[["Source","|","Bold","Italic","|","NumberedList","BulletedList","Blockquote","|","JustifyLeft","JustifyCenter","JustifyRight","|","Link","Unlink","|","Image","|","Undo"],["Redo"]]' + 'editor[settings][toolbar][buttons]' => json_encode($expected_settings['toolbar']['buttons']), ); $this->drupalPost(NULL, $edit, t('Save configuration')); - $expected_settings['toolbar']['buttons'][0][17] = '|'; - $expected_settings['toolbar']['buttons'][0][18] = 'Undo'; - $expected_settings['toolbar']['buttons'][1][] = 'Redo'; $editor = entity_load('editor', 'filtered_html'); $this->assertTrue($editor instanceof Editor, 'An Editor config entity exists.'); $this->assertIdentical($expected_settings, $editor->settings, 'The Editor config entity has the correct settings.'); diff -u b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php --- b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php @@ -92,9 +92,9 @@ $editor->settings['toolbar']['buttons'][1][] = 'Format'; $editor->settings['plugins']['internal']['link_shortcut'] = 'CTRL+K'; $editor->save(); - $expected_config['toolbar'][5]['items'][] = 'Underline'; - $expected_config['toolbar'][7]['items'][] = 'Format'; - $expected_config['toolbar'][8] = '/'; + $expected_config['toolbar'][count($expected_config['toolbar'])-2]['items'][] = 'Underline'; + $expected_config['toolbar'][]['items'][] = 'Format'; + $expected_config['toolbar'][] = '/'; $expected_config['format_tags'] = 'p;h4;h5;h6'; $expected_config['extraPlugins'] = 'llama_contextual,llama_contextual_and_button'; $expected_config['drupalExternalPlugins']['llama_contextual'] = file_create_url('core/modules/ckeditor/tests/modules/js/llama_contextual.js'); @@ -125,7 +125,7 @@ // Customize the configuration. $editor->settings['toolbar']['buttons'][0][] = 'Underline'; $editor->save(); - $expected[5]['items'][] = 'Underline'; + $expected[count($expected)-2]['items'][] = 'Underline'; $this->assertIdentical($expected, $this->ckeditor->buildToolbarJSSetting($editor), '"toolbar" configuration part of JS settings built correctly for customized toolbar.'); // Enable the editor_test module, customize further. @@ -133,7 +133,7 @@ drupal_container()->get('plugin.manager.ckeditor.plugin')->clearCachedDefinitions(); $editor->settings['toolbar']['buttons'][0][] = 'Llama'; $editor->save(); - $expected[5]['items'][] = 'Llama'; + $expected[count($expected)-2]['items'][] = 'Llama'; $this->assertIdentical($expected, $this->ckeditor->buildToolbarJSSetting($editor), '"toolbar" configuration part of JS settings built correctly for customized toolbar with contrib module-provided CKEditor plugin.'); } @@ -225,6 +225,7 @@ protected function getDefaultInternalConfig() { return array( + 'customConfig' => '', 'pasteFromWordPromptCleanup' => TRUE, 'indentClasses' => array('indent1', 'indent2', 'indent3'), 'justifyClasses' => array('align-left', 'align-center', 'align-right', 'align-justify'), @@ -241,13 +242,12 @@ protected function getDefaultToolbarConfig() { return array( - 0 => array('items' => array('Source')), - 1 => array('items' => array('Bold', 'Italic')), - 2 => array('items' => array('NumberedList', 'BulletedList', 'Blockquote')), - 3 => array('items' => array('JustifyLeft', 'JustifyCenter', 'JustifyRight')), - 4 => array('items' => array('Link', 'Unlink')), - 5 => array('items' => array('Image', 'Maximize')), - 6 => '/' + 0 => array('items' => array('Bold', 'Italic')), + 1 => array('items' => array('Link', 'Unlink')), + 2 => array('items' => array('BulletedList', 'NumberedList')), + 3 => array('items' => array('Blockquote', 'Image')), + 4 => array('items' => array('Source')), + 5 => '/' ); }