diff --git a/core/modules/ckeditor/js/ckeditor.js b/core/modules/ckeditor/js/ckeditor.js index acd2cf25509..8c8af022aca 100644 --- a/core/modules/ckeditor/js/ckeditor.js +++ b/core/modules/ckeditor/js/ckeditor.js @@ -10,6 +10,15 @@ format.editorSettings.drupal = { format: format.format }; + + // CKEditor initializes itself in a read-only state if the 'disabled' + // attribute is set. It does not respect the 'readonly' attribute, + // however, so we set the 'readOnly' configuration property manually in + // that case. + if (element.hasAttribute('readonly')) { + format.editorSettings.readOnly = true; + } + return !!CKEDITOR.replace(element, format.editorSettings); }, diff --git a/core/modules/editor/editor.module b/core/modules/editor/editor.module index 9da1540e4f6..00ab94cc54f 100644 --- a/core/modules/editor/editor.module +++ b/core/modules/editor/editor.module @@ -257,9 +257,9 @@ function editor_pre_render_format($element) { } // filter_process_format() copies properties to the expanded 'value' child - // element. Skip this text format widget, if it contains no 'format' or when - // the current user does not have access to edit the value. - if (!isset($element['format']) || !empty($element['value']['#disabled'])) { + // element, including the #pre_render property. Skip this text format widget, + // if it contains no 'format'. + if (!isset($element['format'])) { return $element; } $format_ids = array_keys($element['format']['format']['#options']); diff --git a/core/modules/editor/src/Tests/EditorLoadingTest.php b/core/modules/editor/src/Tests/EditorLoadingTest.php index 59dde52c07f..94b1b8898e5 100644 --- a/core/modules/editor/src/Tests/EditorLoadingTest.php +++ b/core/modules/editor/src/Tests/EditorLoadingTest.php @@ -146,11 +146,12 @@ class EditorLoadingTest extends WebTestBase { )); // The untrusted user tries to edit content that is written in a text format - // that (s)he is not allowed to use. + // that (s)he is not allowed to use. The editor is still loaded. CKEditor, + // for example, supports being loaded in a disabled state. $this->drupalGet('node/1/edit'); list( , $editor_settings_present, $editor_js_present, $body, $format_selector) = $this->getThingsToCheck(); - $this->assertFalse($editor_settings_present, 'No Text Editor module settings.'); - $this->assertFalse($editor_js_present, 'No Text Editor JavaScript.'); + $this->assertTrue($editor_settings_present, 'Text Editor module settings.'); + $this->assertTrue($editor_js_present, 'Text Editor JavaScript.'); $this->assertTrue(count($body) === 1, 'A body field exists.'); $this->assertFieldByXPath('//textarea[@id="edit-body-0-value" and @disabled="disabled"]', t('This field has been disabled because you do not have sufficient permissions to edit it.'), 'Text format access denied message found.'); $this->assertTrue(count($format_selector) === 0, 'No text format selector exists on the page.');