Commit a464d065 authored by catch's avatar catch

Issue #2105939 by Wim Leers, vijaycs85: Make sure all YML files in Editor...

Issue #2105939 by Wim Leers, vijaycs85: Make sure all YML files in Editor module has no type-casting to string + config system changes broke image uploading in editors.
parent b15aed57
...@@ -72,10 +72,7 @@ public function settingsForm(array $form, array &$form_state, Editor $editor) { ...@@ -72,10 +72,7 @@ public function settingsForm(array $form, array &$form_state, Editor $editor) {
form_load_include($form_state, 'inc', 'editor', 'editor.admin'); form_load_include($form_state, 'inc', 'editor', 'editor.admin');
$form['image_upload'] = editor_image_upload_settings_form($editor); $form['image_upload'] = editor_image_upload_settings_form($editor);
$form['image_upload']['#attached']['library'][] = array('ckeditor', 'drupal.ckeditor.drupalimage.admin'); $form['image_upload']['#attached']['library'][] = array('ckeditor', 'drupal.ckeditor.drupalimage.admin');
$form['image_upload']['#element_validate'] = array( $form['image_upload']['#element_validate'][] = array($this, 'validateImageUploadSettings');
array($this, 'validateImageUploadSettings'),
);
return $form; return $form;
} }
...@@ -87,6 +84,7 @@ public function settingsForm(array $form, array &$form_state, Editor $editor) { ...@@ -87,6 +84,7 @@ public function settingsForm(array $form, array &$form_state, Editor $editor) {
* *
* @see \Drupal\editor\Form\EditorImageDialog * @see \Drupal\editor\Form\EditorImageDialog
* @see editor_image_upload_settings_form() * @see editor_image_upload_settings_form()
* @see editor_image_upload_settings_validate()
*/ */
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'];
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
use Drupal\editor\Entity\Editor; use Drupal\editor\Entity\Editor;
use Drupal\Component\Utility\NestedArray;
/** /**
* Subform constructor to configure the text editor's image upload settings. * Subform constructor to configure the text editor's image upload settings.
...@@ -104,7 +105,7 @@ function editor_image_upload_settings_form(Editor $editor) { ...@@ -104,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' => $editor->image_upload['max_dimensions']['width'], '#default_value' => (empty($editor->image_upload['max_dimensions']['width'])) ? '' : $editor->image_upload['max_dimensions']['width'],
'#size' => 8, '#size' => 8,
'#maxlength' => 8, '#maxlength' => 8,
'#min' => 1, '#min' => 1,
...@@ -117,7 +118,7 @@ function editor_image_upload_settings_form(Editor $editor) { ...@@ -117,7 +118,7 @@ function editor_image_upload_settings_form(Editor $editor) {
'#title' => t('Height'), '#title' => t('Height'),
'#title_display' => 'invisible', '#title_display' => 'invisible',
'#type' => 'number', '#type' => 'number',
'#default_value' => $editor->image_upload['max_dimensions']['height'], '#default_value' => (empty($editor->image_upload['max_dimensions']['height'])) ? '' : $editor->image_upload['max_dimensions']['height'],
'#size' => 8, '#size' => 8,
'#maxlength' => 8, '#maxlength' => 8,
'#min' => 1, '#min' => 1,
...@@ -127,5 +128,30 @@ function editor_image_upload_settings_form(Editor $editor) { ...@@ -127,5 +128,30 @@ function editor_image_upload_settings_form(Editor $editor) {
'#states' => $show_if_image_uploads_enabled, '#states' => $show_if_image_uploads_enabled,
); );
$form['#element_validate'] = array(
'editor_image_upload_settings_validate',
);
return $form; return $form;
} }
/**
* #element_validate handler for editor_image_upload_settings_validate().
*
* Ensures each form item's value is cast to the proper type.
*
* @see \Drupal\editor\Form\EditorImageDialog
* @ingroup forms
*/
function editor_image_upload_settings_validate(array $element, array &$form_state) {
$cast_value = function($type, $element) use (&$form_state) {
$section = $element['#parents'];
$value = NestedArray::getValue($form_state['values'], $section);
settype($value, $type);
NestedArray::setValue($form_state['values'], $section, $value);
};
$cast_value('bool', $element['status']);
$cast_value('int', $element['max_dimensions']['width']);
$cast_value('int', $element['max_dimensions']['height']);
}
...@@ -82,7 +82,7 @@ public function buildForm(array $form, array &$form_state, FilterFormat $filter_ ...@@ -82,7 +82,7 @@ public function buildForm(array $form, array &$form_state, FilterFormat $filter_
// If the editor has image uploads enabled, show a managed_file form item, // If the editor has image uploads enabled, show a managed_file form item,
// otherwise show a (file URL) text form item. // otherwise show a (file URL) text form item.
if ($editor->image_upload['status'] === '1') { if ($editor->image_upload['status']) {
$form['attributes']['src']['#access'] = FALSE; $form['attributes']['src']['#access'] = FALSE;
$form['attributes']['src']['#required'] = FALSE; $form['attributes']['src']['#required'] = FALSE;
} }
......
...@@ -32,12 +32,12 @@ settings: ...@@ -32,12 +32,12 @@ settings:
stylescombo: stylescombo:
styles: '' styles: ''
image_upload: image_upload:
status: '1' status: true
scheme: public scheme: public
directory: inline-images directory: inline-images
max_size: '' max_size: ''
max_dimensions: max_dimensions:
width: '' width: 0
height: '' height: 0
status: '1' status: true
langcode: en langcode: en
...@@ -45,12 +45,12 @@ settings: ...@@ -45,12 +45,12 @@ settings:
stylescombo: stylescombo:
styles: '' styles: ''
image_upload: image_upload:
status: '1' status: true
scheme: public scheme: public
directory: inline-images directory: inline-images
max_size: '' max_size: ''
max_dimensions: max_dimensions:
width: '' width: 0
height: '' height: 0
status: '1' status: true
langcode: en langcode: en
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment