Skip to content

Commit

Permalink
Issue #94: Add SVG support for drag-and-drop upload
Browse files Browse the repository at this point in the history
  • Loading branch information
indigoxela committed Apr 18, 2024
1 parent a11de24 commit 277737e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
16 changes: 15 additions & 1 deletion tinymce.module
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ function _tinymce_js_settings($format, array $existing_settings) {

// Drag-and-drop upload.
if ($format->editor_settings['image_upload']['status']) {
$extensions = image_get_supported_extensions();
$extensions = _tinymce_supported_image_extensions();
$options['tiny_options']['images_file_types'] = implode(',', $extensions);
$options['tiny_options']['images_upload_url'] = _tinymce_images_upload_url($format);
$options['tiny_options']['automatic_uploads'] = TRUE;
Expand All @@ -237,6 +237,20 @@ function _tinymce_js_settings($format, array $existing_settings) {
return $options;
}

/**
* Custom callback to file extensions to consider as image.
*
* @return array
*/
function _tinymce_supported_image_extensions() {
$extensions = image_get_supported_extensions();
// Available since Backdrop 1.28 ... @todo maybe.
if (function_exists('file_get_svg_support') && file_get_svg_support()) {
$extensions[] = 'svg';
}
return $extensions;
}

/**
* Helper for an improvised dependency check.
*
Expand Down
3 changes: 2 additions & 1 deletion tinymce.pages.inc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ function tinymce_image_upload($format) {
}

$destination = $upload_settings['scheme'] . '://' . $upload_settings['directory'];
$extensions = _tinymce_supported_image_extensions();
$validators = array(
'file_validate_is_image' => array(),
'file_validate_extensions' => array(implode(' ', $extensions)),
);
if ($upload_settings['max_size']) {
$validators['file_validate_size'] = array(parse_size($upload_settings['max_size']));
Expand Down

0 comments on commit 277737e

Please sign in to comment.