core/modules/ckeditor/ckeditor.module | 2 +- .../js/plugins/drupalimagecaption/plugin.js | 18 ++++- .../js/plugins/drupalimagecaption/theme.js | 5 ++ .../Plugin/CKEditorPlugin/DrupalImageCaption.php | 2 +- .../lib/Drupal/editor/Form/EditorImageDialog.php | 69 ++++++++++---------- 5 files changed, 57 insertions(+), 39 deletions(-) diff --git a/core/modules/ckeditor/ckeditor.module b/core/modules/ckeditor/ckeditor.module index ea02cfb..24a0f85 100644 --- a/core/modules/ckeditor/ckeditor.module +++ b/core/modules/ckeditor/ckeditor.module @@ -150,7 +150,7 @@ function ckeditor_theme() { function ckeditor_ckeditor_css_alter(array &$css, Editor $editor) { $filters = array(); if (!empty($editor->format)) { - $filters = filter_format_load($editor->format) + $filters = entity_load('filter_format', $editor->format) ->filters() ->getAll(); } diff --git a/core/modules/ckeditor/js/plugins/drupalimagecaption/plugin.js b/core/modules/ckeditor/js/plugins/drupalimagecaption/plugin.js index 944bc74..eeb6c7b 100644 --- a/core/modules/ckeditor/js/plugins/drupalimagecaption/plugin.js +++ b/core/modules/ckeditor/js/plugins/drupalimagecaption/plugin.js @@ -38,6 +38,7 @@ CKEDITOR.plugins.add('drupalimagecaption', { // Save the initial widget data. this.setData({ + 'data-editor-file-uuid': image.getAttribute('data-editor-file-uuid'), src: image.getAttribute('src'), width: image.getAttribute('width') || '', height: image.getAttribute('height') || '', @@ -54,10 +55,18 @@ CKEDITOR.plugins.add('drupalimagecaption', { // Called after initialization and on "data" changes. data: function () { + if (this.data['data-editor-file-uuid'] !== null) { + this.parts.image.setAttribute('data-editor-file-uuid', this.data['data-editor-file-uuid']); + this.parts.image.setAttribute('data-cke-saved-data-editor-file-uuid', this.data['data-editor-file-uuid']); + } this.parts.image.setAttribute('src', this.data.src); + this.parts.image.setAttribute('data-cke-saved-src', this.data.src); this.parts.image.setAttribute('alt', this.data.alt); + this.parts.image.setAttribute('data-cke-saved-alt', this.data.alt); this.parts.image.setAttribute('width', this.data.width); + this.parts.image.setAttribute('data-cke-saved-width', this.data.width); this.parts.image.setAttribute('height', this.data.height); + this.parts.image.setAttribute('data-cke-saved-height', this.data.height); // Float the wrapper too. if (this.data.data_align === null) { @@ -119,18 +128,23 @@ CKEDITOR.plugins.add('drupalimagecaption', { return; } + editor.fire('saveSnapshot'); + // Build the HTML for the widget. var html = '. if (returnValues.hasCaption) { html += ' data-caption=""'; + html += ' data-cke-saved-data-caption=""'; } if (returnValues.attributes.data_align && returnValues.attributes.data_align !== 'none') { html += ' data-align="' + returnValues.attributes.data_align + '"'; + html += ' data-cke-saved-data-align="' + returnValues.attributes.data_align + '"'; } html += '/>'; html += '
'; 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 d311c2c..8fb20fe 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/CKEditorPlugin/DrupalImageCaption.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/CKEditorPlugin/DrupalImageCaption.php @@ -68,7 +68,7 @@ public function getConfig(Editor $editor) { function isEnabled(Editor $editor) { $filters = array(); if (!empty($editor->format)) { - $filters = filter_format_load($editor->format) + $filters = entity_load('filter_format', $editor->format) ->filters() ->getAll(); } diff --git a/core/modules/editor/lib/Drupal/editor/Form/EditorImageDialog.php b/core/modules/editor/lib/Drupal/editor/Form/EditorImageDialog.php index 81b2053..2f9a78d 100644 --- a/core/modules/editor/lib/Drupal/editor/Form/EditorImageDialog.php +++ b/core/modules/editor/lib/Drupal/editor/Form/EditorImageDialog.php @@ -7,19 +7,17 @@ namespace Drupal\editor\Form; -use Drupal\Core\Form\FormInterface; +use Drupal\Core\Form\FormBase; use Drupal\filter\Entity\FilterFormat; use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\HtmlCommand; use Drupal\editor\Ajax\EditorDialogSave; use Drupal\Core\Ajax\CloseModalDialogCommand; -use Drupal\Core\StreamWrapper\LocalStream; -use Drupal\file\FileInterface; /** * Provides an image dialog for text editors. */ -class EditorImageDialog implements FormInterface { +class EditorImageDialog extends FormBase { /** * {@inheritdoc} @@ -37,7 +35,10 @@ public function getFormID() { public function buildForm(array $form, array &$form_state, FilterFormat $filter_format = NULL) { // The default values are set directly from $_POST, provided by the // editor plugin opening the dialog. - $input = isset($form_state['input']['editor_object']) ? $form_state['input']['editor_object'] : array(); + if (!isset($form_state['image_element'])) { + $form_state['image_element'] = isset($form_state['input']['editor_object']) ? $form_state['input']['editor_object'] : array(); + } + $image_element = $form_state['image_element']; $form['#tree'] = TRUE; $form['#attached']['library'][] = array('editor', 'drupal.editor.dialog'); @@ -55,11 +56,11 @@ public function buildForm(array $form, array &$form_state, FilterFormat $filter_ } $max_filesize = min(parse_size($editor->image_upload['max_size']), file_upload_max_size()); - $existing_file = isset($input['data-editor-file-uuid']) ? entity_load_by_uuid('file', $input['data-editor-file-uuid']) : NULL; + $existing_file = isset($image_element['data-editor-file-uuid']) ? entity_load_by_uuid('file', $image_element['data-editor-file-uuid']) : NULL; $fid = $existing_file ? $existing_file->id() : NULL; $form['fid'] = array( - '#title' => t('Image'), + '#title' => $this->t('Image'), '#type' => 'managed_file', '#upload_location' => $editor->image_upload['scheme'] . '://' .$editor->image_upload['directory'], '#default_value' => $fid ? array($fid) : NULL, @@ -72,9 +73,9 @@ public function buildForm(array $form, array &$form_state, FilterFormat $filter_ ); $form['attributes']['src'] = array( - '#title' => t('URL'), + '#title' => $this->t('URL'), '#type' => 'textfield', - '#default_value' => isset($input['src']) ? $input['src'] : '', + '#default_value' => isset($image_element['src']) ? $image_element['src'] : '', '#maxlength' => 2048, '#required' => TRUE, ); @@ -83,28 +84,30 @@ public function buildForm(array $form, array &$form_state, FilterFormat $filter_ // otherwise show a (file URL) text form item. if ($editor->image_upload['status'] === '1') { $form['attributes']['src']['#access'] = FALSE; + $form['attributes']['src']['#required'] = FALSE; } else { $form['fid']['#access'] = FALSE; + $form['fid']['#required'] = FALSE; } $form['attributes']['alt'] = array( - '#title' => t('Alternative text'), + '#title' => $this->t('Alternative text'), '#type' => 'textfield', - '#default_value' => isset($input['alt']) ? $input['alt'] : '', + '#default_value' => isset($image_element['alt']) ? $image_element['alt'] : '', '#maxlength' => 2048, ); $form['dimensions'] = array( '#type' => 'item', - '#title' => t('Image size'), + '#title' => $this->t('Image size'), '#field_prefix' => '
', '#field_suffix' => '
', ); $form['dimensions']['width'] = array( - '#title' => t('Width'), + '#title' => $this->t('Width'), '#title_display' => 'invisible', '#type' => 'number', - '#default_value' => isset($input['width']) ? $input['width'] : '', + '#default_value' => isset($image_element['width']) ? $image_element['width'] : '', '#size' => 8, '#maxlength' => 8, '#min' => 1, @@ -114,10 +117,10 @@ public function buildForm(array $form, array &$form_state, FilterFormat $filter_ '#parents' => array('attributes', 'width'), ); $form['dimensions']['height'] = array( - '#title' => t('Height'), + '#title' => $this->t('Height'), '#title_display' => 'invisible', '#type' => 'number', - '#default_value' => isset($input['height']) ? $input['height'] : '', + '#default_value' => isset($image_element['height']) ? $image_element['height'] : '', '#size' => 8, '#maxlength' => 8, '#min' => 1, @@ -129,17 +132,17 @@ public function buildForm(array $form, array &$form_state, FilterFormat $filter_ // When Drupal core's filter_caption is being used, the text editor may // offer the ability to change the alignment. - if (isset($input['data_align'])) { + if (isset($image_element['data_align'])) { $form['align'] = array( - '#title' => t('Align'), + '#title' => $this->t('Align'), '#type' => 'radios', '#options' => array( - 'none' => t('None'), - 'left' => t('Left'), - 'center' => t('Center'), - 'right' => t('Right'), + 'none' => $this->t('None'), + 'left' => $this->t('Left'), + 'center' => $this->t('Center'), + 'right' => $this->t('Right'), ), - '#default_value' => $input['data_align'] === '' ? 'none' : $input['data_align'], + '#default_value' => $image_element['data_align'] === '' ? 'none' : $image_element['data_align'], '#wrapper_attributes' => array('class' => array('container-inline')), '#attributes' => array('class' => array('container-inline')), '#parents' => array('attributes', 'data_align'), @@ -148,23 +151,23 @@ public function buildForm(array $form, array &$form_state, FilterFormat $filter_ // When Drupal core's filter_caption is being used, the text editor may // offer the ability to in-place edit the image's caption: show a toggle. - if (isset($input['hasCaption'])) { + if (isset($image_element['hasCaption'])) { $form['caption'] = array( - '#title' => t('Caption'), + '#title' => $this->t('Caption'), '#type' => 'checkbox', - '#default_value' => $input['hasCaption'] === 'true', + '#default_value' => $image_element['hasCaption'] === 'true', '#parents' => array('hasCaption'), ); } - $has_align_or_caption = isset($input['data_align']) || isset($input['hasCaption']); - if ($has_align_or_caption && isset($input['isInline']) && $input['isInline'] === 'true') { + $has_align_or_caption = isset($image_element['data_align']) || isset($image_element['hasCaption']); + if ($has_align_or_caption && isset($image_element['isInline']) && $image_element['isInline'] === 'true') { $form['align']['#type'] = 'item'; $form['align']['#description'] = t('Inline images cannot be aligned.'); unset($form['align']['#default_value']); $form['caption']['#type'] = 'item'; - $form['caption']['#description'] = t('Inline images cannot be captioned.'); + $form['caption']['#description'] = $this->t('Inline images cannot be captioned.'); $form['caption']['#wrapper_attributes'] = array('class' => array('container-inline')); $form['caption']['#attributes'] = array('class' => array('container-inline')); } @@ -174,7 +177,7 @@ public function buildForm(array $form, array &$form_state, FilterFormat $filter_ ); $form['actions']['save_modal'] = array( '#type' => 'submit', - '#value' => t('Save'), + '#value' => $this->t('Save'), // No regular submit-handler. This form only works via JavaScript. '#submit' => array(), '#ajax' => array( @@ -189,12 +192,6 @@ public function buildForm(array $form, array &$form_state, FilterFormat $filter_ /** * {@inheritdoc} */ - public function validateForm(array &$form, array &$form_state) { - } - - /** - * {@inheritdoc} - */ public function submitForm(array &$form, array &$form_state) { $response = new AjaxResponse();