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) {
// @see \Drupal\Core\Config\Entity\ConfigEntityStorage::MAX_ID_LENGTH
// @todo Consider moving this to a protected method on the parent class, and
// 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(
'@id' => $entity->{$this->idKey},
'@id' => $entity->get($this->idKey),
'@length' => self::MAX_ID_LENGTH,
)));
}
......
......@@ -39,7 +39,8 @@ function template_preprocess_ckeditor_settings_toolbar(&$variables) {
}
$button_groups = 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();
foreach ($row as $group) {
foreach ($group['items'] as $button_name) {
......
......@@ -27,7 +27,7 @@ interface CKEditorPluginContextualInterface extends CKEditorPluginInterface {
/**
* 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
* A configured text editor object.
......
......@@ -79,11 +79,15 @@ public function getFile();
/**
* 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
* it may not yet contain plugin-specific settings, because the user may not
* yet have configured the form.
* The editor's settings can be retrieved via $editor->getSettings(), but be
* aware that it may not yet contain plugin-specific settings, because the
* user may not yet have configured the form.
* 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
* A configured text editor object.
......
......@@ -67,8 +67,9 @@ public function getEnabledPluginFiles(Editor $editor, $include_internal_plugins
$plugins = array_keys($this->getDefinitions());
// Flatten each row.
$toolbar_rows = array();
foreach ($editor->settings['toolbar']['rows'] as $row_number => $row) {
$toolbar_rows[] = array_reduce($editor->settings['toolbar']['rows'][$row_number], function (&$result, $button_group) {
$settings = $editor->getSettings();
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']);
}, array());
}
......
......@@ -85,7 +85,7 @@ public function settingsForm(array $form, array &$form_state, Editor $editor) {
*/
function validateImageUploadSettings(array $element, array &$form_state) {
$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']);
}
......
......@@ -69,7 +69,8 @@ function isEnabled(Editor $editor) {
// enabled.
if ($editor->getFilterFormat()->filters('filter_caption')->status) {
$enabled = FALSE;
foreach ($editor->settings['toolbar']['rows'] as $row) {
$settings = $editor->getSettings();
foreach ($settings['toolbar']['rows'] as $row) {
foreach ($row as $group) {
foreach ($group['items'] as $button) {
if ($button === 'DrupalImage') {
......
......@@ -55,8 +55,9 @@ public function getConfig(Editor $editor) {
// Add the format_tags setting, if its button is enabled.
$toolbar_rows = array();
foreach ($editor->settings['toolbar']['rows'] as $row_number => $row) {
$toolbar_rows[] = array_reduce($editor->settings['toolbar']['rows'][$row_number], function (&$result, $button_group) {
$settings = $editor->getSettings();
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']);
}, array());
}
......@@ -259,7 +260,7 @@ protected function generateFormatTagsSetting(Editor $editor) {
$possible_format_tags = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'pre');
foreach ($possible_format_tags as $tag) {
$input = '<' . $tag . '>TEST</' . $tag . '>';
$output = trim(check_markup($input, $editor->format, '', TRUE));
$output = trim(check_markup($input, $editor->id(), '', TRUE));
if ($input == $output) {
$format_tags[] = $tag;
}
......
......@@ -42,10 +42,11 @@ public function getFile() {
*/
public function getConfig(Editor $editor) {
$config = array();
if (!isset($editor->settings['plugins']['stylescombo']['styles'])) {
$settings = $editor->getSettings();
if (!isset($settings['plugins']['stylescombo']['styles'])) {
return $config;
}
$styles = $editor->settings['plugins']['stylescombo']['styles'];
$styles = $settings['plugins']['stylescombo']['styles'];
$config['stylesSet'] = $this->generateStylesSetSetting($styles);
return $config;
}
......@@ -68,8 +69,9 @@ public function getButtons() {
public function settingsForm(array $form, array &$form_state, Editor $editor) {
// Defaults.
$config = array('styles' => '');
if (isset($editor->settings['plugins']['stylescombo'])) {
$config = $editor->settings['plugins']['stylescombo'];
$settings = $editor->getSettings();
if (isset($settings['plugins']['stylescombo'])) {
$config = $settings['plugins']['stylescombo'];
}
$form['styles'] = array(
......
......@@ -129,6 +129,8 @@ public function getDefaultSettings() {
* {@inheritdoc}
*/
public function settingsForm(array $form, array &$form_state, EditorEntity $editor) {
$settings = $editor->getSettings();
$ckeditor_settings_toolbar = array(
'#theme' => 'ckeditor_settings_toolbar',
'#editor' => $editor,
......@@ -153,7 +155,7 @@ public function settingsForm(array $form, array &$form_state, EditorEntity $edit
$form['toolbar']['button_groups'] = array(
'#type' => 'textarea',
'#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')),
);
......@@ -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);
......@@ -380,7 +382,9 @@ public function getLibraries(EditorEntity $editor) {
*/
public function buildToolbarJSSetting(EditorEntity $editor) {
$toolbar = array();
foreach ($editor->settings['toolbar']['rows'] as $row) {
$settings = $editor->getSettings();
foreach ($settings['toolbar']['rows'] as $row) {
foreach ($row as $group) {
$toolbar[] = $group;
}
......
......@@ -130,7 +130,7 @@ function testAdmin() {
$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.');
$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.
$this->drupalGet('admin/config/content/formats/manage/filtered_html');
......@@ -141,7 +141,7 @@ function testAdmin() {
$expected_settings['plugins']['stylescombo']['styles'] = "h1.title|Title\np.callout|Callout\n\n";
$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.');
$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
// done via drag and drop, but here we can only emulate the end result of
......@@ -158,7 +158,7 @@ function testAdmin() {
$this->drupalPostForm(NULL, $edit, t('Save configuration'));
$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.');
$this->assertIdentical($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
// Now enable the ckeditor_test module, which provides one configurable
// CKEditor plugin — this should not affect the Editor config entity.
......@@ -170,7 +170,7 @@ function testAdmin() {
$this->assertTrue(count($ultra_llama_mode_checkbox) === 1, 'The "Ultra llama mode" checkbox exists and is not checked.');
$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.');
$this->assertIdentical($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
// Finally, check the "Ultra llama mode" checkbox.
$this->drupalGet('admin/config/content/formats/manage/filtered_html');
......@@ -184,7 +184,7 @@ function testAdmin() {
$expected_settings['plugins']['llama_contextual_and_button']['ultra_llama_mode'] = 1;
$editor = entity_load('editor', 'filtered_html');
$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() {
// don't test that here.
\Drupal::moduleHandler()->install(array('ckeditor_test'));
$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();
$this->drupalGet('node/add/article');
list($settings, $editor_settings_present, $editor_js_present, $body, $format_selector) = $this->getThingsToCheck();
......
......@@ -104,8 +104,10 @@ function testEnabledPlugins() {
// cause the LlamaContextual and LlamaContextualAndButton plugins to be
// enabled. Finally, we will add the "Strike" button back again, which would
// cause all three plugins to be enabled.
$original_toolbar = $editor->settings['toolbar'];
$editor->settings['toolbar']['rows'][0][0]['items'][] = 'Llama';
$settings = $editor->getSettings();
$original_toolbar = $settings['toolbar'];
$settings['toolbar']['rows'][0][0]['items'][] = 'Llama';
$editor->setSettings($settings);
$editor->save();
$file = array();
$file['b'] = 'core/modules/ckeditor/tests/modules/js/llama_button.js';
......@@ -114,13 +116,15 @@ function testEnabledPlugins() {
$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(array('internal' => NULL) + $expected, $this->manager->getEnabledPluginFiles($editor, TRUE), 'The LlamaButton and LlamaContextualAndButton plugins are enabled.');
$editor->settings['toolbar'] = $original_toolbar;
$editor->settings['toolbar']['rows'][0][0]['items'][] = 'Strike';
$settings['toolbar'] = $original_toolbar;
$settings['toolbar']['rows'][0][0]['items'][] = 'Strike';
$editor->setSettings($settings);
$editor->save();
$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(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();
$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.');
......
......@@ -109,8 +109,10 @@ function testGetJSSettings() {
$this->container->get('plugin.manager.editor')->clearCachedDefinitions();
$this->ckeditor = $this->container->get('plugin.manager.editor')->createInstance('ckeditor');
$this->container->get('plugin.manager.ckeditor.plugin')->clearCachedDefinitions();
$editor->settings['toolbar']['rows'][0][0]['items'][] = 'Strike';
$editor->settings['toolbar']['rows'][0][0]['items'][] = 'Format';
$settings = $editor->getSettings();
$settings['toolbar']['rows'][0][0]['items'][] = 'Strike';
$settings['toolbar']['rows'][0][0]['items'][] = 'Format';
$editor->setSettings($settings);
$editor->save();
$expected_config['toolbar'][0]['items'][] = 'Strike';
$expected_config['toolbar'][0]['items'][] = 'Format';
......@@ -210,7 +212,9 @@ function testBuildToolbarJSSetting() {
$this->assertIdentical($expected, $this->ckeditor->buildToolbarJSSetting($editor), '"toolbar" configuration part of JS settings built correctly for default toolbar.');
// 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();
$expected[0]['items'][] = 'Strike';
$this->assertIdentical($expected, $this->ckeditor->buildToolbarJSSetting($editor), '"toolbar" configuration part of JS settings built correctly for customized toolbar.');
......@@ -219,8 +223,9 @@ function testBuildToolbarJSSetting() {
$this->enableModules(array('ckeditor_test'));
$this->container->get('plugin.manager.ckeditor.plugin')->clearCachedDefinitions();
// Override the label of a toolbar component.
$editor->settings['toolbar']['rows'][0][0]['name'] = 'JunkScience';
$editor->settings['toolbar']['rows'][0][0]['items'][] = 'Llama';
$settings['toolbar']['rows'][0][0]['name'] = 'JunkScience';
$settings['toolbar']['rows'][0][0]['items'][] = 'Llama';
$editor->setSettings($settings);
$editor->save();
$expected[0]['name'] = 'JunkScience';
$expected[0]['items'][] = 'Llama';
......@@ -258,7 +263,9 @@ function testInternalGetConfig() {
$this->assertIdentical($expected, $internal_plugin->getConfig($editor), '"Internal" plugin configuration built correctly for default toolbar.');
// 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';
$this->assertIdentical($expected, $internal_plugin->getConfig($editor), '"Internal" plugin configuration built correctly for customized toolbar.');
}
......@@ -271,23 +278,28 @@ function testStylesComboGetConfig() {
$stylescombo_plugin = $this->container->get('plugin.manager.ckeditor.plugin')->createInstance('stylescombo');
// Styles dropdown/button enabled: new setting should be present.
$editor->settings['toolbar']['rows'][0][0]['items'][] = 'Styles';
$editor->settings['plugins']['stylescombo']['styles'] = '';
$settings = $editor->getSettings();
$settings['toolbar']['rows'][0][0]['items'][] = 'Styles';
$settings['plugins']['stylescombo']['styles'] = '';
$editor->setSettings($settings);
$editor->save();
$expected['stylesSet'] = array();
$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
// the end result.
$editor->settings['plugins']['stylescombo']['styles'] = " \n";
$settings['plugins']['stylescombo']['styles'] = " \n";
$editor->setSettings($settings);
$editor->save();
$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();
$this->assertIdentical($expected, $stylescombo_plugin->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.');
// 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();
$expected['stylesSet'] = array(
array('name' => 'Title', 'element' => 'h1', 'attributes' => array('class' => 'title')),
......@@ -297,18 +309,21 @@ function testStylesComboGetConfig() {
// Same configuration, but now interspersed with nonsense. Should yield the
// 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();
$this->assertIdentical($expected, $stylescombo_plugin->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.');
// 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();
$expected['stylesSet'] = array(array('name' => 'Title', 'element' => 'h1'));
$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.
$editor->settings['plugins']['stylescombo']['styles'] = "h1";
$settings['plugins']['stylescombo']['styles'] = "h1";
$editor->setSettings($settings);
$editor->save();
$expected['stylesSet'] = FALSE;
$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
*/
function isEnabled(Editor $editor) {
// 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) {
if (in_array('Strike', $group['items'])) {
return TRUE;
......
......@@ -29,7 +29,8 @@ class LlamaContextualAndButton extends Llama implements CKEditorPluginContextual
*/
function isEnabled(Editor $editor) {
// 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) {
if (in_array('Strike', $group['items'])) {
return TRUE;
......@@ -63,8 +64,9 @@ function getFile() {
function settingsForm(array $form, array &$form_state, Editor $editor) {
// Defaults.
$config = array('ultra_llama_mode' => FALSE);
if (isset($editor->settings['plugins']['llama_contextual_and_button'])) {
$config = $editor->settings['plugins']['llama_contextual_and_button'];
$settings = $editor->getSettings();
if (isset($settings['plugins']['llama_contextual_and_button'])) {
$config = $settings['plugins']['llama_contextual_and_button'];
}
$form['ultra_llama_mode'] = array(
......
......@@ -27,8 +27,8 @@
*/
function editor_image_upload_settings_form(Editor $editor) {
// Defaults.
$editor->image_upload = isset($editor->image_upload) ? $editor->image_upload : array();
$editor->image_upload += array(
$image_upload = $editor->getImageUploadSettings();
$image_upload += array(
'status' => FALSE,
'scheme' => file_default_scheme(),
'directory' => 'inline-images',
......@@ -39,7 +39,7 @@ function editor_image_upload_settings_form(Editor $editor) {
$form['status'] = array(
'#type' => 'checkbox',
'#title' => t('Enable image uploads'),
'#default_value' => $editor->image_upload['status'],
'#default_value' => $image_upload['status'],
'#attributes' => array(
'data-editor-image-upload' => 'status',
),
......@@ -60,7 +60,7 @@ function editor_image_upload_settings_form(Editor $editor) {
$form['scheme'] = array(
'#type' => 'radios',
'#title' => t('File storage'),
'#default_value' => $editor->image_upload['scheme'],
'#default_value' => $image_upload['scheme'],
'#options' => $options,
'#states' => $show_if_image_uploads_enabled,
'#access' => count($options) > 1,
......@@ -75,7 +75,7 @@ function editor_image_upload_settings_form(Editor $editor) {
$form['directory'] = array(
'#type' => 'textfield',
'#default_value' => $editor->image_upload['directory'],
'#default_value' => $image_upload['directory'],
'#title' => t('Upload directory'),
'#description' => t("A directory relative to Drupal's files directory where uploaded images will be stored."),
'#states' => $show_if_image_uploads_enabled,
......@@ -84,7 +84,7 @@ function editor_image_upload_settings_form(Editor $editor) {
$default_max_size = format_size(file_upload_max_size());
$form['max_size'] = array(
'#type' => 'textfield',
'#default_value' => $editor->image_upload['max_size'],
'#default_value' => $image_upload['max_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)),
'#maxlength' => 20,
......@@ -105,7 +105,7 @@ function editor_image_upload_settings_form(Editor $editor) {
'#title' => t('Width'),
'#title_display' => 'invisible',
'#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,
'#maxlength' => 8,
'#min' => 1,
......@@ -118,7 +118,7 @@ function editor_image_upload_settings_form(Editor $editor) {
'#title' => t('Height'),
'#title_display' => 'invisible',
'#type' => 'number',
'#default_value' => (empty($editor->image_upload['max_dimensions']['height'])) ? '' : $editor->image_upload['max_dimensions']['height'],
'#default_value' => (empty($image_upload['max_dimensions']['height'])) ? '' : $image_upload['max_dimensions']['height'],
'#size' => 8,
'#maxlength' => 8,
'#min' => 1,
......
......@@ -79,7 +79,7 @@ function editor_form_filter_admin_overview_alter(&$form, $form_state) {
$editors = \Drupal::service('plugin.manager.editor')->getDefinitions();
foreach (Element::children($form['formats']) as $format_id) {
$editor = editor_load($format_id);
$editor_name = ($editor && isset($editors[$editor->editor])) ? $editors[$editor->editor]['label'] : drupal_placeholder('—');
$editor_name = ($editor && isset($editors[$editor->getEditor()])) ? $editors[$editor->getEditor()]['label'] : drupal_placeholder('—');
$editor_column['editor'] = array('#markup' => $editor_name);
$position = array_search('name', array_keys($form['formats'][$format_id])) + 1;
$start = array_splice($form['formats'][$format_id], 0, $position, $editor_column);
......@@ -110,7 +110,7 @@ function editor_form_filter_format_form_alter(&$form, &$form_state) {
'#title' => t('Text editor'),
'#options' => $editor_options,
'#empty_option' => t('None'),
'#default_value' => $editor ? $editor->editor : '',
'#default_value' => $editor ? $editor->getEditor() : '',
'#ajax' => array(
'trigger_as' => array('name' => 'editor_configure'),
'callback' => 'editor_form_filter_admin_form_ajax',
......@@ -152,7 +152,7 @@ function editor_form_filter_format_form_alter(&$form, &$form_state) {
// Add editor-specific validation and submit handlers.
if ($editor) {
$plugin = $manager->createInstance($editor->editor);
$plugin = $manager->createInstance($editor->getEditor());
$settings_form = array();
$settings_form['#element_validate'][] = array($plugin, 'settingsFormValidate');
$form['editor']['settings']['subform'] = $plugin->settingsForm($settings_form, $form_state, $editor);
......@@ -173,7 +173,7 @@ function editor_form_filter_admin_format_editor_configure($form, &$form_state) {
if ($form_state['values']['editor']['editor'] === '') {
$form_state['editor'] = FALSE;
}
elseif (empty($editor) || $form_state['values']['editor']['editor'] !== $editor->editor) {
elseif (empty($editor) || $form_state['values']['editor']['editor'] !== $editor->getEditor()) {
$editor = entity_create('editor', array(
'format' => $form_state['controller']->getEntity()->id(),
'editor' => $form_state['values']['editor']['editor'],
......@@ -216,7 +216,7 @@ function editor_form_filter_admin_format_submit($form, &$form_state) {
// Delete the existing editor if disabling or switching between editors.
$format_id = $form_state['controller']->getEntity()->id();
$original_editor = editor_load($format_id);
if ($original_editor && $original_editor->editor != $form_state['values']['editor']) {
if ($original_editor && $original_editor->getEditor() != $form_state['values']['editor']) {
$original_editor->delete();
}
......@@ -224,8 +224,8 @@ function editor_form_filter_admin_format_submit($form, &$form_state) {
if (!empty($form_state['editor'])) {
// Ensure the text format is set: when creating a new text format, this
// would equal the empty string.
$form_state['editor']->format = $format_id;
$form_state['editor']->settings = $form_state['values']['editor']['settings'];
$form_state['editor']->set('format', $format_id);
$form_state['editor']->setSettings($form_state['values']['editor']['settings']);
$form_state['editor']->save();
}
}
......@@ -359,7 +359,7 @@ function editor_filter_xss($html, FilterFormatInterface $format, FilterFormatInt
// If the text editor associated with this text format guarantees security,
// then we also don't need text editor XSS filtering.
$definition = \Drupal::service('plugin.manager.editor')->getDefinition($editor->editor);
$definition = \Drupal::service('plugin.manager.editor')->getDefinition($editor->getEditor());
if ($definition['is_xss_safe'] === TRUE) {
return FALSE;
}
......
......@@ -21,4 +21,48 @@ interface EditorInterface extends ConfigEntityInterface {
*/
public function getFilterFormat();
/**
* Returns the associated text editor plugin ID.
*
* @return string
* The text editor plugin ID.
*/
public function getEditor();
/**
* Returns the text editor plugin-specific settings.
*
* @return array
* A structured array containing all text editor settings.
*/
public function getSettings();
/**
* Sets the text editor plugin-specific settings.
*
* @param array $settings
* The structured array containing all text editor settings.
*
* @return $this
*/
public function setSettings(array $settings);
/**
* Returns the image upload settings.
*
* @return array
* A structured array containing image upload settings.
*/
public function getImageUploadSettings();
/**
* Sets the image upload settings.
*
* @param array $image_upload
* The structured array containing image upload settings.
*
* @return $this
*/
public function setImageUploadSettings(array $image_upload);
}
......@@ -28,29 +28,31 @@ class Editor extends ConfigEntityBase implements EditorInterface {
* is associated.
*
* @var string
*
* @see getFilterFormat()
*/
public $format;
protected $format;
/**
* The name (plugin ID) of the text editor.
*
* @var string
*/
public $editor;
protected $editor;
/**
* The array of text editor plugin-specific settings for the text editor.
* The structured array of text editor plugin-specific settings.
*
* @var array
*/
public $settings = array();
protected $settings = array();
/**
* The array of image upload settings for the text editor.
* The structured array of image upload settings.
*
* @var array
*/
public $image_upload = array();
protected $image_upload = array();
/**
* The filter format this text editor is associated with.
......@@ -123,4 +125,58 @@ protected function editorPluginManager() {
return $this->editorPluginManager;
}
/**
* {@inheritdoc}
*/
public function getEditor() {
return $this->editor;
}
/**
* {@inheritdoc}
*/
public function getSettings() {
return $this->settings;
}
/**
* {@inheritdoc}
*/
public function setSettings(array $settings) {
$this->settings = $settings;
return $this;
}
/**
* {@inheritdoc}
*/
public function getImageUploadSettings() {
return $this->image_upload;
}
/**
* {@inheritdoc}
*/
public function setImageUploadSettings(array $image_upload_settings) {
$this->image_upload = $image_upload_settings;
return $this;
}
/**
* {@inheritdoc}
*/
public function toArray() {
$properties = parent::toArray();
$names = array(
'format',
'editor',
'settings',
'image_upload',
);
foreach ($names as $name) {
$properties[$name] = $this->get($name);
}
return $properties;
}