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) {
form_load_include($form_state, 'inc', 'editor', 'editor.admin');
$form['image_upload'] = editor_image_upload_settings_form($editor);
$form['image_upload']['#attached']['library'][] = array('ckeditor', 'drupal.ckeditor.drupalimage.admin');
$form['image_upload']['#element_validate'] = array(
array($this, 'validateImageUploadSettings'),
);
$form['image_upload']['#element_validate'][] = array($this, 'validateImageUploadSettings');
return $form;
}
......@@ -87,6 +84,7 @@ public function settingsForm(array $form, array &$form_state, Editor $editor) {
*
* @see \Drupal\editor\Form\EditorImageDialog
* @see editor_image_upload_settings_form()
* @see editor_image_upload_settings_validate()
*/
function validateImageUploadSettings(array $element, array &$form_state) {
$settings = &$form_state['values']['editor']['settings']['plugins']['drupalimage']['image_upload'];
......
......@@ -6,6 +6,7 @@
*/
use Drupal\editor\Entity\Editor;
use Drupal\Component\Utility\NestedArray;
/**
* Subform constructor to configure the text editor's image upload settings.
......@@ -104,7 +105,7 @@ function editor_image_upload_settings_form(Editor $editor) {
'#title' => t('Width'),
'#title_display' => 'invisible',
'#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,
'#maxlength' => 8,
'#min' => 1,
......@@ -117,7 +118,7 @@ function editor_image_upload_settings_form(Editor $editor) {
'#title' => t('Height'),
'#title_display' => 'invisible',
'#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,
'#maxlength' => 8,
'#min' => 1,
......@@ -127,5 +128,30 @@ function editor_image_upload_settings_form(Editor $editor) {
'#states' => $show_if_image_uploads_enabled,
);
$form['#element_validate'] = array(
'editor_image_upload_settings_validate',
);
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_
// If the editor has image uploads enabled, show a managed_file 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']['#required'] = FALSE;
}
......
......@@ -32,12 +32,12 @@ settings:
stylescombo:
styles: ''
image_upload:
status: '1'
status: true
scheme: public
directory: inline-images
max_size: ''
max_dimensions:
width: ''
height: ''
status: '1'
width: 0
height: 0
status: true
langcode: en
......@@ -45,12 +45,12 @@ settings:
stylescombo:
styles: ''
image_upload:
status: '1'
status: true
scheme: public
directory: inline-images
max_size: ''
max_dimensions:
width: ''
height: ''
status: '1'
width: 0
height: 0
status: true
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