summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2014-05-20 09:59:25 (GMT)
committerAlex Pott2014-05-20 09:59:25 (GMT)
commitbc5bfc9166509a18f587cbf7b977a31c03313266 (patch)
tree43de516b43ebe0e669c326553c96bda1dd8bd1bb
parentfe26eb63faee8dbe8ae027d0fd5306d7966fe53b (diff)
Issue #2207777 by Wim Leers, pjonckiere, Rajesh Ashok | alexpott: Can not configure editor whilst creating a new text format.
-rw-r--r--core/modules/ckeditor/ckeditor.module4
-rw-r--r--core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/CKEditorPlugin/DrupalImageCaption.php4
-rw-r--r--core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/CKEditorPlugin/Internal.php9
-rw-r--r--core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorAdminTest.php68
-rw-r--r--core/modules/editor/lib/Drupal/editor/EditorInterface.php16
-rw-r--r--core/modules/editor/lib/Drupal/editor/Entity/Editor.php7
-rw-r--r--core/modules/filter/lib/Drupal/filter/FilterFormatInterface.php2
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 @@ class DrupalImageCaption extends PluginBase implements CKEditorPluginInterface,
* {@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 @@ class Internal extends CKEditorPluginBase {
* 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 @@ class CKEditorAdminTest extends WebTestBase {
$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 @@ class CKEditorAdminTest extends WebTestBase {
$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" <select> when a text editor is available.
+ $select = $this->xpath('//select[@name="editor[editor]"]');
+ $select_is_disabled = $this->xpath('//select[@name="editor[editor]" and @disabled="disabled"]');
+ $options = $this->xpath('//select[@name="editor[editor]"]/option');
+ $this->assertTrue(count($select) === 1, 'The Text Editor select exists.');
+ $this->assertTrue(count($select_is_disabled) === 0, 'The Text Editor select is not disabled.');
+ $this->assertTrue(count($options) === 2, 'The Text Editor select has two options.');
+ $this->assertTrue(((string) $options[0]) === 'None', 'Option 1 in the Text Editor select is "None".');
+ $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.');
+
+ // Name our fancy new text format, select the "CKEditor" editor and click
+ // the "Configure" button.
+ $edit = array(
+ 'name' => 'My amazing text format',
+ 'format' => 'amazing_format',
+ 'editor[editor]' => 'ckeditor',
+ );
+ $this->drupalPostAjaxForm(NULL, $edit, 'editor_configure');
+ $filter_format = entity_load('filter_format', 'amazing_format');
+ $this->assertFalse($filter_format, 'No FilterFormat config entity exists yet.');
+ $editor = entity_load('editor', 'amazing_format');
+ $this->assertFalse($editor, 'No Editor config entity exists yet.');
+
+ // Ensure the toolbar buttons configuration value is initialized to the
+ // default value.
+ $ckeditor = $this->container->get('plugin.manager.editor')->createInstance('ckeditor');
+ $default_settings = $ckeditor->getDefaultSettings();
+ $expected_buttons_value = json_encode($default_settings['toolbar']['rows']);
+ $this->assertFieldByName('editor[settings][toolbar][button_groups]', $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 create both a new text format and an associated text
+ // editor.
+ $this->drupalPostForm(NULL, $edit, t('Save configuration'));
+
+ // Ensure a FilterFormat object exists now.
+ $filter_format = entity_load('filter_format', 'amazing_format');
+ $this->assertTrue($filter_format instanceof FilterFormatInterface, 'A FilterFormat config entity exists now.');
+
+ // Ensure an Editor object exists now, with the proper settings.
+ $expected_settings = $default_settings;
+ $expected_settings['plugins']['stylescombo']['styles'] = '';
+ $editor = entity_load('editor', 'amazing_format');
+ $this->assertTrue($editor instanceof Editor, 'An Editor config entity exists now.');
+ $this->assertIdentical($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
+ }
+
}
diff --git a/core/modules/editor/lib/Drupal/editor/EditorInterface.php b/core/modules/editor/lib/Drupal/editor/EditorInterface.php
index 7847011..1631ec9 100644
--- a/core/modules/editor/lib/Drupal/editor/EditorInterface.php
+++ b/core/modules/editor/lib/Drupal/editor/EditorInterface.php
@@ -15,9 +15,23 @@ use Drupal\Core\Config\Entity\ConfigEntityInterface;
interface EditorInterface extends ConfigEntityInterface {
/**
+ * Returns whether this text editor has an associated filter format.
+ *
+ * A text editor may be created at the same time as the filter format it's
+ * going to be associated with; in that case, no filter format object is
+ * available yet.
+ *
+ * @return bool
+ */
+ public function hasAssociatedFilterFormat();
+
+ /**
* Returns the filter format this text editor is associated with.
*
- * @return \Drupal\filter\FilterFormatInterface
+ * This could be NULL if the associated filter format is still being created.
+ * @see hasAssociatedFilterFormat()
+ *
+ * @return \Drupal\filter\FilterFormatInterface|null
*/
public function getFilterFormat();
diff --git a/core/modules/editor/lib/Drupal/editor/Entity/Editor.php b/core/modules/editor/lib/Drupal/editor/Entity/Editor.php
index 8378102..40aff70 100644
--- a/core/modules/editor/lib/Drupal/editor/Entity/Editor.php
+++ b/core/modules/editor/lib/Drupal/editor/Entity/Editor.php
@@ -105,6 +105,13 @@ class Editor extends ConfigEntityBase implements EditorInterface {
/**
* {@inheritdoc}
*/
+ public function hasAssociatedFilterFormat() {
+ return $this->format !== NULL;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
public function getFilterFormat() {
if (!$this->filterFormat) {
$this->filterFormat = \Drupal::entityManager()->getStorage('filter_format')->load($this->format);
diff --git a/core/modules/filter/lib/Drupal/filter/FilterFormatInterface.php b/core/modules/filter/lib/Drupal/filter/FilterFormatInterface.php
index df93354..e0b3c84 100644
--- a/core/modules/filter/lib/Drupal/filter/FilterFormatInterface.php
+++ b/core/modules/filter/lib/Drupal/filter/FilterFormatInterface.php
@@ -2,7 +2,7 @@
/**
* @file
- * Contains \Drupal\filter\Entity\FilterFormatInterface.
+ * Contains \Drupal\filter\FilterFormatInterface.
*/
namespace Drupal\filter;