Commit 396cacba authored by webchick's avatar webchick

Issue #2030605 by tim.plunkett, mr.baileys, webwarrior, Wim Leers | plopesc:...

Issue #2030605 by tim.plunkett, mr.baileys, webwarrior, Wim Leers | plopesc: Expand Editor with methods.
parent c056f6df
...@@ -220,9 +220,9 @@ public function save(EntityInterface $entity) { ...@@ -220,9 +220,9 @@ public function save(EntityInterface $entity) {
// @see \Drupal\Core\Config\Entity\ConfigEntityStorage::MAX_ID_LENGTH // @see \Drupal\Core\Config\Entity\ConfigEntityStorage::MAX_ID_LENGTH
// @todo Consider moving this to a protected method on the parent class, and // @todo Consider moving this to a protected method on the parent class, and
// abstracting it for all entity types. // abstracting it for all entity types.
if (strlen($entity->{$this->idKey}) > self::MAX_ID_LENGTH) { if (strlen($entity->get($this->idKey)) > self::MAX_ID_LENGTH) {
throw new ConfigEntityIdLengthException(String::format('Configuration entity ID @id exceeds maximum allowed length of @length characters.', array( throw new ConfigEntityIdLengthException(String::format('Configuration entity ID @id exceeds maximum allowed length of @length characters.', array(
'@id' => $entity->{$this->idKey}, '@id' => $entity->get($this->idKey),
'@length' => self::MAX_ID_LENGTH, '@length' => self::MAX_ID_LENGTH,
))); )));
} }
......
...@@ -39,7 +39,8 @@ function template_preprocess_ckeditor_settings_toolbar(&$variables) { ...@@ -39,7 +39,8 @@ function template_preprocess_ckeditor_settings_toolbar(&$variables) {
} }
$button_groups = array(); $button_groups = array();
$active_buttons = array(); $active_buttons = array();
foreach ($editor->settings['toolbar']['rows'] as $row_number => $row) { $settings = $editor->getSettings();
foreach ($settings['toolbar']['rows'] as $row_number => $row) {
$button_groups[$row_number] = array(); $button_groups[$row_number] = array();
foreach ($row as $group) { foreach ($row as $group) {
foreach ($group['items'] as $button_name) { foreach ($group['items'] as $button_name) {
......
...@@ -27,7 +27,7 @@ interface CKEditorPluginContextualInterface extends CKEditorPluginInterface { ...@@ -27,7 +27,7 @@ interface CKEditorPluginContextualInterface extends CKEditorPluginInterface {
/** /**
* Checks if this plugin should be enabled based on the editor configuration. * Checks if this plugin should be enabled based on the editor configuration.
* *
* The editor's settings can be found in $editor->settings. * The editor's settings can be retrieved via $editor->getSettings().
* *
* @param \Drupal\editor\Entity\Editor $editor * @param \Drupal\editor\Entity\Editor $editor
* A configured text editor object. * A configured text editor object.
......
...@@ -79,11 +79,15 @@ public function getFile(); ...@@ -79,11 +79,15 @@ public function getFile();
/** /**
* Returns the additions to CKEDITOR.config for a specific CKEditor instance. * Returns the additions to CKEDITOR.config for a specific CKEditor instance.
* *
* The editor's settings can be found in $editor->settings, but be aware that * The editor's settings can be retrieved via $editor->getSettings(), but be
* it may not yet contain plugin-specific settings, because the user may not * aware that it may not yet contain plugin-specific settings, because the
* yet have configured the form. * user may not yet have configured the form.
* If there are plugin-specific settings (verify with isset()), they can be * If there are plugin-specific settings (verify with isset()), they can be
* found at $editor->settings['plugins'][$plugin_id]. * found at
* @code
* $settings = $editor->getSettings();
* $plugin_specific_settings = $settings['plugins'][$plugin_id];
* @endcode
* *
* @param \Drupal\editor\Entity\Editor $editor * @param \Drupal\editor\Entity\Editor $editor
* A configured text editor object. * A configured text editor object.
......
...@@ -67,8 +67,9 @@ public function getEnabledPluginFiles(Editor $editor, $include_internal_plugins ...@@ -67,8 +67,9 @@ public function getEnabledPluginFiles(Editor $editor, $include_internal_plugins
$plugins = array_keys($this->getDefinitions()); $plugins = array_keys($this->getDefinitions());
// Flatten each row. // Flatten each row.
$toolbar_rows = array(); $toolbar_rows = array();
foreach ($editor->settings['toolbar']['rows'] as $row_number => $row) { $settings = $editor->getSettings();
$toolbar_rows[] = array_reduce($editor->settings['toolbar']['rows'][$row_number], function (&$result, $button_group) { foreach ($settings['toolbar']['rows'] as $row_number => $row) {
$toolbar_rows[] = array_reduce($settings['toolbar']['rows'][$row_number], function (&$result, $button_group) {
return array_merge($result, $button_group['items']); return array_merge($result, $button_group['items']);
}, array()); }, array());
} }
......
...@@ -85,7 +85,7 @@ public function settingsForm(array $form, array &$form_state, Editor $editor) { ...@@ -85,7 +85,7 @@ public function settingsForm(array $form, array &$form_state, Editor $editor) {
*/ */
function validateImageUploadSettings(array $element, array &$form_state) { function validateImageUploadSettings(array $element, array &$form_state) {
$settings = &$form_state['values']['editor']['settings']['plugins']['drupalimage']['image_upload']; $settings = &$form_state['values']['editor']['settings']['plugins']['drupalimage']['image_upload'];
$form_state['editor']->image_upload = $settings; $form_state['editor']->setImageUploadSettings($settings);
unset($form_state['values']['editor']['settings']['plugins']['drupalimage']); unset($form_state['values']['editor']['settings']['plugins']['drupalimage']);
} }
......
...@@ -69,7 +69,8 @@ function isEnabled(Editor $editor) { ...@@ -69,7 +69,8 @@ function isEnabled(Editor $editor) {
// enabled. // enabled.
if ($editor->getFilterFormat()->filters('filter_caption')->status) { if ($editor->getFilterFormat()->filters('filter_caption')->status) {
$enabled = FALSE; $enabled = FALSE;
foreach ($editor->settings['toolbar']['rows'] as $row) { $settings = $editor->getSettings();
foreach ($settings['toolbar']['rows'] as $row) {
foreach ($row as $group) { foreach ($row as $group) {
foreach ($group['items'] as $button) { foreach ($group['items'] as $button) {
if ($button === 'DrupalImage') { if ($button === 'DrupalImage') {
......
...@@ -55,8 +55,9 @@ public function getConfig(Editor $editor) { ...@@ -55,8 +55,9 @@ public function getConfig(Editor $editor) {
// Add the format_tags setting, if its button is enabled. // Add the format_tags setting, if its button is enabled.
$toolbar_rows = array(); $toolbar_rows = array();
foreach ($editor->settings['toolbar']['rows'] as $row_number => $row) { $settings = $editor->getSettings();
$toolbar_rows[] = array_reduce($editor->settings['toolbar']['rows'][$row_number], function (&$result, $button_group) { foreach ($settings['toolbar']['rows'] as $row_number => $row) {
$toolbar_rows[] = array_reduce($settings['toolbar']['rows'][$row_number], function (&$result, $button_group) {
return array_merge($result, $button_group['items']); return array_merge($result, $button_group['items']);
}, array()); }, array());
} }
...@@ -259,7 +260,7 @@ protected function generateFormatTagsSetting(Editor $editor) { ...@@ -259,7 +260,7 @@ protected function generateFormatTagsSetting(Editor $editor) {
$possible_format_tags = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'pre'); $possible_format_tags = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'pre');
foreach ($possible_format_tags as $tag) { foreach ($possible_format_tags as $tag) {
$input = '<' . $tag . '>TEST</' . $tag . '>'; $input = '<' . $tag . '>TEST</' . $tag . '>';
$output = trim(check_markup($input, $editor->format, '', TRUE)); $output = trim(check_markup($input, $editor->id(), '', TRUE));
if ($input == $output) { if ($input == $output) {
$format_tags[] = $tag; $format_tags[] = $tag;
} }
......
...@@ -42,10 +42,11 @@ public function getFile() { ...@@ -42,10 +42,11 @@ public function getFile() {
*/ */
public function getConfig(Editor $editor) { public function getConfig(Editor $editor) {
$config = array(); $config = array();
if (!isset($editor->settings['plugins']['stylescombo']['styles'])) { $settings = $editor->getSettings();
if (!isset($settings['plugins']['stylescombo']['styles'])) {
return $config; return $config;
} }
$styles = $editor->settings['plugins']['stylescombo']['styles']; $styles = $settings['plugins']['stylescombo']['styles'];
$config['stylesSet'] = $this->generateStylesSetSetting($styles); $config['stylesSet'] = $this->generateStylesSetSetting($styles);
return $config; return $config;
} }
...@@ -68,8 +69,9 @@ public function getButtons() { ...@@ -68,8 +69,9 @@ public function getButtons() {
public function settingsForm(array $form, array &$form_state, Editor $editor) { public function settingsForm(array $form, array &$form_state, Editor $editor) {
// Defaults. // Defaults.
$config = array('styles' => ''); $config = array('styles' => '');
if (isset($editor->settings['plugins']['stylescombo'])) { $settings = $editor->getSettings();
$config = $editor->settings['plugins']['stylescombo']; if (isset($settings['plugins']['stylescombo'])) {
$config = $settings['plugins']['stylescombo'];
} }
$form['styles'] = array( $form['styles'] = array(
......
...@@ -129,6 +129,8 @@ public function getDefaultSettings() { ...@@ -129,6 +129,8 @@ public function getDefaultSettings() {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function settingsForm(array $form, array &$form_state, EditorEntity $editor) { public function settingsForm(array $form, array &$form_state, EditorEntity $editor) {
$settings = $editor->getSettings();
$ckeditor_settings_toolbar = array( $ckeditor_settings_toolbar = array(
'#theme' => 'ckeditor_settings_toolbar', '#theme' => 'ckeditor_settings_toolbar',
'#editor' => $editor, '#editor' => $editor,
...@@ -153,7 +155,7 @@ public function settingsForm(array $form, array &$form_state, EditorEntity $edit ...@@ -153,7 +155,7 @@ public function settingsForm(array $form, array &$form_state, EditorEntity $edit
$form['toolbar']['button_groups'] = array( $form['toolbar']['button_groups'] = array(
'#type' => 'textarea', '#type' => 'textarea',
'#title' => t('Toolbar buttons'), '#title' => t('Toolbar buttons'),
'#default_value' => json_encode($editor->settings['toolbar']['rows']), '#default_value' => json_encode($settings['toolbar']['rows']),
'#attributes' => array('class' => array('ckeditor-toolbar-textarea')), '#attributes' => array('class' => array('ckeditor-toolbar-textarea')),
); );
...@@ -206,7 +208,7 @@ public function settingsForm(array $form, array &$form_state, EditorEntity $edit ...@@ -206,7 +208,7 @@ public function settingsForm(array $form, array &$form_state, EditorEntity $edit
) )
), ),
), ),
'plugins' => $editor->settings['plugins'], 'plugins' => $settings['plugins'],
), ),
)); ));
$config = $this->getJSSettings($fake_editor); $config = $this->getJSSettings($fake_editor);
...@@ -380,7 +382,9 @@ public function getLibraries(EditorEntity $editor) { ...@@ -380,7 +382,9 @@ public function getLibraries(EditorEntity $editor) {
*/ */
public function buildToolbarJSSetting(EditorEntity $editor) { public function buildToolbarJSSetting(EditorEntity $editor) {
$toolbar = array(); $toolbar = array();
foreach ($editor->settings['toolbar']['rows'] as $row) {
$settings = $editor->getSettings();
foreach ($settings['toolbar']['rows'] as $row) {
foreach ($row as $group) { foreach ($row as $group) {
$toolbar[] = $group; $toolbar[] = $group;
} }
......
...@@ -130,7 +130,7 @@ function testAdmin() { ...@@ -130,7 +130,7 @@ function testAdmin() {
$expected_settings['plugins']['stylescombo']['styles'] = ''; $expected_settings['plugins']['stylescombo']['styles'] = '';
$editor = entity_load('editor', 'filtered_html'); $editor = entity_load('editor', 'filtered_html');
$this->assertTrue($editor instanceof Editor, 'An Editor config entity exists now.'); $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.'); $this->assertIdentical($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
// Configure the Styles plugin, and ensure the updated settings are saved. // Configure the Styles plugin, and ensure the updated settings are saved.
$this->drupalGet('admin/config/content/formats/manage/filtered_html'); $this->drupalGet('admin/config/content/formats/manage/filtered_html');
...@@ -141,7 +141,7 @@ function testAdmin() { ...@@ -141,7 +141,7 @@ function testAdmin() {
$expected_settings['plugins']['stylescombo']['styles'] = "h1.title|Title\np.callout|Callout\n\n"; $expected_settings['plugins']['stylescombo']['styles'] = "h1.title|Title\np.callout|Callout\n\n";
$editor = entity_load('editor', 'filtered_html'); $editor = entity_load('editor', 'filtered_html');
$this->assertTrue($editor instanceof Editor, 'An Editor config entity exists.'); $this->assertTrue($editor instanceof Editor, 'An Editor config entity exists.');
$this->assertIdentical($expected_settings, $editor->settings, 'The Editor config entity has the correct settings.'); $this->assertIdentical($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
// Change the buttons that appear on the toolbar (in JavaScript, this is // 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 // done via drag and drop, but here we can only emulate the end result of
...@@ -158,7 +158,7 @@ function testAdmin() { ...@@ -158,7 +158,7 @@ function testAdmin() {
$this->drupalPostForm(NULL, $edit, t('Save configuration')); $this->drupalPostForm(NULL, $edit, t('Save configuration'));
$editor = entity_load('editor', 'filtered_html'); $editor = entity_load('editor', 'filtered_html');
$this->assertTrue($editor instanceof Editor, 'An Editor config entity exists.'); $this->assertTrue($editor instanceof Editor, 'An Editor config entity exists.');
$this->assertIdentical($expected_settings, $editor->settings, 'The Editor config entity has the correct settings.'); $this->assertIdentical($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
// Now enable the ckeditor_test module, which provides one configurable // Now enable the ckeditor_test module, which provides one configurable
// CKEditor plugin — this should not affect the Editor config entity. // CKEditor plugin — this should not affect the Editor config entity.
...@@ -170,7 +170,7 @@ function testAdmin() { ...@@ -170,7 +170,7 @@ function testAdmin() {
$this->assertTrue(count($ultra_llama_mode_checkbox) === 1, 'The "Ultra llama mode" checkbox exists and is not checked.'); $this->assertTrue(count($ultra_llama_mode_checkbox) === 1, 'The "Ultra llama mode" checkbox exists and is not checked.');
$editor = entity_load('editor', 'filtered_html'); $editor = entity_load('editor', 'filtered_html');
$this->assertTrue($editor instanceof Editor, 'An Editor config entity exists.'); $this->assertTrue($editor instanceof Editor, 'An Editor config entity exists.');
$this->assertIdentical($expected_settings, $editor->settings, 'The Editor config entity has the correct settings.'); $this->assertIdentical($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
// Finally, check the "Ultra llama mode" checkbox. // Finally, check the "Ultra llama mode" checkbox.
$this->drupalGet('admin/config/content/formats/manage/filtered_html'); $this->drupalGet('admin/config/content/formats/manage/filtered_html');
...@@ -184,7 +184,7 @@ function testAdmin() { ...@@ -184,7 +184,7 @@ function testAdmin() {
$expected_settings['plugins']['llama_contextual_and_button']['ultra_llama_mode'] = 1; $expected_settings['plugins']['llama_contextual_and_button']['ultra_llama_mode'] = 1;
$editor = entity_load('editor', 'filtered_html'); $editor = entity_load('editor', 'filtered_html');
$this->assertTrue($editor instanceof Editor, 'An Editor config entity exists.'); $this->assertTrue($editor instanceof Editor, 'An Editor config entity exists.');
$this->assertIdentical($expected_settings, $editor->settings); $this->assertIdentical($expected_settings, $editor->getSettings());
} }
} }
...@@ -123,7 +123,9 @@ function testLoading() { ...@@ -123,7 +123,9 @@ function testLoading() {
// don't test that here. // don't test that here.
\Drupal::moduleHandler()->install(array('ckeditor_test')); \Drupal::moduleHandler()->install(array('ckeditor_test'));
$this->container->get('plugin.manager.ckeditor.plugin')->clearCachedDefinitions(); $this->container->get('plugin.manager.ckeditor.plugin')->clearCachedDefinitions();
$editor->settings['toolbar']['buttons'][0][] = 'Llama'; $editor_settings = $editor->getSettings();
$editor_settings['toolbar']['buttons'][0][] = 'Llama';
$editor->setSettings($editor_settings);
$editor->save(); $editor->save();
$this->drupalGet('node/add/article'); $this->drupalGet('node/add/article');
list($settings, $editor_settings_present, $editor_js_present, $body, $format_selector) = $this->getThingsToCheck(); list($settings, $editor_settings_present, $editor_js_present, $body, $format_selector) = $this->getThingsToCheck();
......
...@@ -104,8 +104,10 @@ function testEnabledPlugins() { ...@@ -104,8 +104,10 @@ function testEnabledPlugins() {
// cause the LlamaContextual and LlamaContextualAndButton plugins to be // cause the LlamaContextual and LlamaContextualAndButton plugins to be
// enabled. Finally, we will add the "Strike" button back again, which would // enabled. Finally, we will add the "Strike" button back again, which would
// cause all three plugins to be enabled. // cause all three plugins to be enabled.
$original_toolbar = $editor->settings['toolbar']; $settings = $editor->getSettings();
$editor->settings['toolbar']['rows'][0][0]['items'][] = 'Llama'; $original_toolbar = $settings['toolbar'];
$settings['toolbar']['rows'][0][0]['items'][] = 'Llama';
$editor->setSettings($settings);
$editor->save(); $editor->save();
$file = array(); $file = array();
$file['b'] = 'core/modules/ckeditor/tests/modules/js/llama_button.js'; $file['b'] = 'core/modules/ckeditor/tests/modules/js/llama_button.js';
...@@ -114,13 +116,15 @@ function testEnabledPlugins() { ...@@ -114,13 +116,15 @@ function testEnabledPlugins() {
$expected = $enabled_plugins + array('llama_button' => $file['b'], 'llama_contextual_and_button' => $file['cb']); $expected = $enabled_plugins + array('llama_button' => $file['b'], 'llama_contextual_and_button' => $file['cb']);
$this->assertIdentical($expected, $this->manager->getEnabledPluginFiles($editor), 'The LlamaButton and LlamaContextualAndButton plugins are enabled.'); $this->assertIdentical($expected, $this->manager->getEnabledPluginFiles($editor), 'The LlamaButton and LlamaContextualAndButton plugins are enabled.');
$this->assertIdentical(array('internal' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LlamaButton and LlamaContextualAndButton plugins are enabled.'); $this->assertIdentical(array('internal' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LlamaButton and LlamaContextualAndButton plugins are enabled.');
$editor->settings['toolbar'] = $original_toolbar; $settings['toolbar'] = $original_toolbar;
$editor->settings['toolbar']['rows'][0][0]['items'][] = 'Strike'; $settings['toolbar']['rows'][0][0]['items'][] = 'Strike';
$editor->setSettings($settings);
$editor->save(); $editor->save();
$expected = $enabled_plugins + array('llama_contextual' => $file['c'], 'llama_contextual_and_button' => $file['cb']); $expected = $enabled_plugins + array('llama_contextual' => $file['c'], 'llama_contextual_and_button' => $file['cb']);
$this->assertIdentical($expected, $this->manager->getEnabledPluginFiles($editor), 'The LLamaContextual and LlamaContextualAndButton plugins are enabled.'); $this->assertIdentical($expected, $this->manager->getEnabledPluginFiles($editor), 'The LLamaContextual and LlamaContextualAndButton plugins are enabled.');
$this->assertIdentical(array('internal' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LlamaContextual and LlamaContextualAndButton plugins are enabled.'); $this->assertIdentical(array('internal' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LlamaContextual and LlamaContextualAndButton plugins are enabled.');
$editor->settings['toolbar']['rows'][0][0]['items'][] = 'Llama'; $settings['toolbar']['rows'][0][0]['items'][] = 'Llama';
$editor->setSettings($settings);
$editor->save(); $editor->save();
$expected = $enabled_plugins + array('llama_button' => $file['b'], 'llama_contextual' => $file['c'], 'llama_contextual_and_button' => $file['cb']); $expected = $enabled_plugins + array('llama_button' => $file['b'], 'llama_contextual' => $file['c'], 'llama_contextual_and_button' => $file['cb']);
$this->assertIdentical($expected, $this->manager->getEnabledPluginFiles($editor), 'The LlamaButton, LlamaContextual and LlamaContextualAndButton plugins are enabled.'); $this->assertIdentical($expected, $this->manager->getEnabledPluginFiles($editor), 'The LlamaButton, LlamaContextual and LlamaContextualAndButton plugins are enabled.');
......
...@@ -109,8 +109,10 @@ function testGetJSSettings() { ...@@ -109,8 +109,10 @@ function testGetJSSettings() {
$this->container->get('plugin.manager.editor')->clearCachedDefinitions(); $this->container->get('plugin.manager.editor')->clearCachedDefinitions();
$this->ckeditor = $this->container->get('plugin.manager.editor')->createInstance('ckeditor'); $this->ckeditor = $this->container->get('plugin.manager.editor')->createInstance('ckeditor');
$this->container->get('plugin.manager.ckeditor.plugin')->clearCachedDefinitions(); $this->container->get('plugin.manager.ckeditor.plugin')->clearCachedDefinitions();
$editor->settings['toolbar']['rows'][0][0]['items'][] = 'Strike'; $settings = $editor->getSettings();
$editor->settings['toolbar']['rows'][0][0]['items'][] = 'Format'; $settings['toolbar']['rows'][0][0]['items'][] = 'Strike';
$settings['toolbar']['rows'][0][0]['items'][] = 'Format';
$editor->setSettings($settings);
$editor->save(); $editor->save();
$expected_config['toolbar'][0]['items'][] = 'Strike'; $expected_config['toolbar'][0]['items'][] = 'Strike';
$expected_config['toolbar'][0]['items'][] = 'Format'; $expected_config['toolbar'][0]['items'][] = 'Format';
...@@ -210,7 +212,9 @@ function testBuildToolbarJSSetting() { ...@@ -210,7 +212,9 @@ function testBuildToolbarJSSetting() {
$this->assertIdentical($expected, $this->ckeditor->buildToolbarJSSetting($editor), '"toolbar" configuration part of JS settings built correctly for default toolbar.'); $this->assertIdentical($expected, $this->ckeditor->buildToolbarJSSetting($editor), '"toolbar" configuration part of JS settings built correctly for default toolbar.');
// Customize the configuration. // Customize the configuration.
$editor->settings['toolbar']['rows'][0][0]['items'][] = 'Strike'; $settings = $editor->getSettings();
$settings['toolbar']['rows'][0][0]['items'][] = 'Strike';
$editor->setSettings($settings);
$editor->save(); $editor->save();
$expected[0]['items'][] = 'Strike'; $expected[0]['items'][] = 'Strike';
$this->assertIdentical($expected, $this->ckeditor->buildToolbarJSSetting($editor), '"toolbar" configuration part of JS settings built correctly for customized toolbar.'); $this->assertIdentical($expected, $this->ckeditor->buildToolbarJSSetting($editor), '"toolbar" configuration part of JS settings built correctly for customized toolbar.');
...@@ -219,8 +223,9 @@ function testBuildToolbarJSSetting() { ...@@ -219,8 +223,9 @@ function testBuildToolbarJSSetting() {
$this->enableModules(array('ckeditor_test')); $this->enableModules(array('ckeditor_test'));
$this->container->get('plugin.manager.ckeditor.plugin')->clearCachedDefinitions(); $this->container->get('plugin.manager.ckeditor.plugin')->clearCachedDefinitions();
// Override the label of a toolbar component. // Override the label of a toolbar component.
$editor->settings['toolbar']['rows'][0][0]['name'] = 'JunkScience'; $settings['toolbar']['rows'][0][0]['name'] = 'JunkScience';
$editor->settings['toolbar']['rows'][0][0]['items'][] = 'Llama'; $settings['toolbar']['rows'][0][0]['items'][] = 'Llama';
$editor->setSettings($settings);
$editor->save(); $editor->save();
$expected[0]['name'] = 'JunkScience'; $expected[0]['name'] = 'JunkScience';
$expected[0]['items'][] = 'Llama'; $expected[0]['items'][] = 'Llama';
...@@ -258,7 +263,9 @@ function testInternalGetConfig() { ...@@ -258,7 +263,9 @@ function testInternalGetConfig() {
$this->assertIdentical($expected, $internal_plugin->getConfig($editor), '"Internal" plugin configuration built correctly for default toolbar.'); $this->assertIdentical($expected, $internal_plugin->getConfig($editor), '"Internal" plugin configuration built correctly for default toolbar.');
// Format dropdown/button enabled: new setting should be present. // Format dropdown/button enabled: new setting should be present.
$editor->settings['toolbar']['rows'][0][0]['items'][] = 'Format'; $settings = $editor->getSettings();
$settings['toolbar']['rows'][0][0]['items'][] = 'Format';
$editor->setSettings($settings);
$expected['format_tags'] = 'p;h4;h5;h6'; $expected['format_tags'] = 'p;h4;h5;h6';
$this->assertIdentical($expected, $internal_plugin->getConfig($editor), '"Internal" plugin configuration built correctly for customized toolbar.'); $this->assertIdentical($expected, $internal_plugin->getConfig($editor), '"Internal" plugin configuration built correctly for customized toolbar.');
} }
...@@ -271,23 +278,28 @@ function testStylesComboGetConfig() { ...@@ -271,23 +278,28 @@ function testStylesComboGetConfig() {
$stylescombo_plugin = $this->container->get('plugin.manager.ckeditor.plugin')->createInstance('stylescombo'); $stylescombo_plugin = $this->container->get('plugin.manager.ckeditor.plugin')->createInstance('stylescombo');
// Styles dropdown/button enabled: new setting should be present. // Styles dropdown/button enabled: new setting should be present.
$editor->settings['toolbar']['rows'][0][0]['items'][] = 'Styles'; $settings = $editor->getSettings();
$editor->settings['plugins']['stylescombo']['styles'] = ''; $settings['toolbar']['rows'][0][0]['items'][] = 'Styles';
$settings['plugins']['stylescombo']['styles'] = '';
$editor->setSettings($settings);
$editor->save(); $editor->save();
$expected['stylesSet'] = array(); $expected['stylesSet'] = array();
$this->assertIdentical($expected, $stylescombo_plugin->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.'); $this->assertIdentical($expected, $stylescombo_plugin->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.');
// Configure the optional "styles" setting in odd ways that shouldn't affect // Configure the optional "styles" setting in odd ways that shouldn't affect
// the end result. // the end result.
$editor->settings['plugins']['stylescombo']['styles'] = " \n"; $settings['plugins']['stylescombo']['styles'] = " \n";
$editor->setSettings($settings);
$editor->save(); $editor->save();
$this->assertIdentical($expected, $stylescombo_plugin->getConfig($editor)); $this->assertIdentical($expected, $stylescombo_plugin->getConfig($editor));
$editor->settings['plugins']['stylescombo']['styles'] = "\r\n \n \r \n "; $settings['plugins']['stylescombo']['styles'] = "\r\n \n \r \n ";
$editor->setSettings($settings);
$editor->save(); $editor->save();
$this->assertIdentical($expected, $stylescombo_plugin->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.'); $this->assertIdentical($expected, $stylescombo_plugin->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.');
// Now configure it properly, the end result should change. // Now configure it properly, the end result should change.
$editor->settings['plugins']['stylescombo']['styles'] = "h1.title|Title\np.mAgical.Callout|Callout"; $settings['plugins']['stylescombo']['styles'] = "h1.title|Title\np.mAgical.Callout|Callout";
$editor->setSettings($settings);
$editor->save(); $editor->save();
$expected['stylesSet'] = array( $expected['stylesSet'] = array(
array('name' => 'Title', 'element' => 'h1', 'attributes' => array('class' => 'title')), array('name' => 'Title', 'element' => 'h1', 'attributes' => array('class' => 'title')),
...@@ -297,18 +309,21 @@ function testStylesComboGetConfig() { ...@@ -297,18 +309,21 @@ function testStylesComboGetConfig() {
// Same configuration, but now interspersed with nonsense. Should yield the // Same configuration, but now interspersed with nonsense. Should yield the
// same result. // same result.
$editor->settings['plugins']['stylescombo']['styles'] = " h1 .title | Title \r \n\r \np.mAgical .Callout|Callout\r"; $settings['plugins']['stylescombo']['styles'] = " h1 .title | Title \r \n\r \np.mAgical .Callout|Callout\r";
$editor->setSettings($settings);
$editor->save(); $editor->save();
$this->assertIdentical($expected, $stylescombo_plugin->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.'); $this->assertIdentical($expected, $stylescombo_plugin->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.');
// Slightly different configuration: class names are optional. // Slightly different configuration: class names are optional.
$editor->settings['plugins']['stylescombo']['styles'] = " h1 | Title "; $settings['plugins']['stylescombo']['styles'] = " h1 | Title ";
$editor->setSettings($settings);
$editor->save(); $editor->save();
$expected['stylesSet'] = array(array('name' => 'Title', 'element' => 'h1')); $expected['stylesSet'] = array(array('name' => 'Title', 'element' => 'h1'));
$this->assertIdentical($expected, $stylescombo_plugin->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.'); $this->assertIdentical($expected, $stylescombo_plugin->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.');
// Invalid syntax should cause stylesSet to be set to FALSE. // Invalid syntax should cause stylesSet to be set to FALSE.
$editor->settings['plugins']['stylescombo']['styles'] = "h1"; $settings['plugins']['stylescombo']['styles'] = "h1";
$editor->setSettings($settings);
$editor->save(); $editor->save();
$expected['stylesSet'] = FALSE; $expected['stylesSet'] = FALSE;
$this->assertIdentical($expected, $stylescombo_plugin->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.'); $this->assertIdentical($expected, $stylescombo_plugin->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.');
......
...@@ -26,7 +26,8 @@ class LlamaContextual extends Llama implements CKEditorPluginContextualInterface ...@@ -26,7 +26,8 @@ class LlamaContextual extends Llama implements CKEditorPluginContextualInterface
*/ */
function isEnabled(Editor $editor) { function isEnabled(Editor $editor) {
// Automatically enable this plugin if the Underline button is enabled. // Automatically enable this plugin if the Underline button is enabled.
foreach ($editor->settings['toolbar']['rows'] as $row) { $settings = $editor->getSettings();
foreach ($settings['toolbar']['rows'] as $row) {
foreach ($row as $group) { foreach ($row as $group) {
if (in_array('Strike', $group['items'])) { if (in_array('Strike', $group['items'])) {
return TRUE; return TRUE;
......
...@@ -29,7 +29,8 @@ class LlamaContextualAndButton extends Llama implements CKEditorPluginContextual ...@@ -29,7 +29,8 @@ class LlamaContextualAndButton extends Llama implements CKEditorPluginContextual
*/ */
function isEnabled(Editor $editor) { function isEnabled(Editor $editor) {
// Automatically enable this plugin if the Strike button is enabled. // Automatically enable this plugin if the Strike button is enabled.
foreach ($editor->settings['toolbar']['rows'] as $row) { $settings = $editor->getSettings();
foreach ($settings['toolbar']['rows'] as $row) {
foreach ($row as $group) { foreach ($row as $group) {
if (in_array('Strike', $group['items'])) { if (in_array('Strike', $group['items'])) {
return TRUE; return TRUE;
...@@ -63,8 +64,9 @@ function getFile() { ...@@ -63,8 +64,9 @@ function getFile() {
function settingsForm(array $form, array &$form_state, Editor $editor) { function settingsForm(array $form, array &$form_state, Editor $editor) {
// Defaults. // Defaults.
$config = array('ultra_llama_mode' => FALSE); $config = array('ultra_llama_mode' => FALSE);
if (isset($editor->settings['plugins']['llama_contextual_and_button'])) { $settings = $editor->getSettings();
$config = $editor->settings['plugins']['llama_contextual_and_button']; if (isset($settings['plugins']['llama_contextual_and_button'])) {
$config = $settings['plugins']['llama_contextual_and_button'];
} }
$form['ultra_llama_mode'] = array( $form['ultra_llama_mode'] = array(
......
...@@ -27,8 +27,8 @@ ...@@ -27,8 +27,8 @@
*/ */
function editor_image_upload_settings_form(Editor $editor) { function editor_image_upload_settings_form(Editor $editor) {
// Defaults. // Defaults.
$editor->image_upload = isset($editor->image_upload) ? $editor->image_upload : array(); $image_upload = $editor->getImageUploadSettings();
$editor->image_upload += array( $image_upload += array(
'status' => FALSE, 'status' => FALSE,
'scheme' => file_default_scheme(), 'scheme' => file_default_scheme(),
'directory' => 'inline-images', 'directory' => 'inline-images',
...@@ -39,7 +39,7 @@ function editor_image_upload_settings_form(Editor $editor) { ...@@ -39,7 +39,7 @@ function editor_image_upload_settings_form(Editor $editor) {
$form['status'] = array( $form['status'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Enable image uploads'), '#title' => t('Enable image uploads'),
'#default_value' => $editor->image_upload['status'], '#default_value' => $image_upload['status'],
'#attributes' => array( '#attributes' => array(
'data-editor-image-upload' => 'status', 'data-editor-image-upload' => 'status',
), ),
...@@ -60,7 +60,7 @@ function editor_image_upload_settings_form(Editor $editor) { ...@@ -60,7 +60,7 @@ function editor_image_upload_settings_form(Editor $editor) {
$form['scheme'] = array( $form['scheme'] = array(
'#type' => 'radios', '#type' => 'radios',
'#title' => t('File storage'), '#title' => t('File storage'),
'#default_value' => $editor->image_upload['scheme'], '#default_value' => $image_upload['scheme'],
'#options' => $options, '#options' => $options,
'#states' => $show_if_image_uploads_enabled, '#states' => $show_if_image_uploads_enabled,
'#access' => count($options) > 1, '#access' => count($options) > 1,
...@@ -75,7 +75,7 @@ function editor_image_upload_settings_form(Editor $editor) { ...@@ -75,7 +75,7 @@ function editor_image_upload_settings_form(Editor $editor) {
$form['directory'] = array( $form['directory'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#default_value' => $editor->image_upload['directory'], '#default_value' => $image_upload['directory'],
'#title' => t('Upload directory'), '#title' => t('Upload directory'),
'#description' => t("A directory relative to Drupal's files directory where uploaded images will be stored."), '#description' => t("A directory relative to Drupal's files directory where uploaded images will be stored."),
'#states' => $show_if_image_uploads_enabled, '#states' => $show_if_image_uploads_enabled,
...@@ -84,7 +84,7 @@ function editor_image_upload_settings_form(Editor $editor) { ...@@ -84,7 +84,7 @@ function editor_image_upload_settings_form(Editor $editor) {
$default_max_size = format_size(file_upload_max_size()); $default_max_size = format_size(file_upload_max_size());
$form['max_size'] = array( $form['max_size'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#default_value' => $editor->image_upload['max_size'], '#default_value' => $image_upload['max_size'],
'#title' => t('Maximum file size'), '#title' => t('Maximum file size'),
'#description' => t('If this is left empty, then the file size will be limited by the PHP maximum upload size of @size.', array('@size' => $default_max_size)), '#description' => t('If this is left empty, then the file size will be limited by the PHP maximum upload size of @size.', array('@size' => $default_max_size)),
'#maxlength' => 20, '#maxlength' => 20,
...@@ -105,7 +105,7 @@ function editor_image_upload_settings_form(Editor $editor) { ...@@ -105,7 +105,7 @@ function editor_image_upload_settings_form(Editor $editor) {
'#title' => t('Width'), '#title' => t('Width'),
'#title_display' => 'invisible', '#title_display' => 'invisible',
'#type' => 'number', '#type' => 'number',
'#default_value' => (empty($editor->image_upload['max_dimensions']['width'])) ? '' : $editor->image_upload['max_dimensions']['width'], '#default_value' => (empty($image_upload['max_dimensions']['width'])) ? '' : $image_upload['max_dimensions']['width'],
'#size' => 8, '#size' => 8,
'#maxlength' => 8, '#maxlength' => 8,
'#min' => 1,