1 filter.pages.inc | filter_format_editor_image_form_submit($form, &$form_state) |
Submit handler for filter_format_editor_image_form().
File
- core/
modules/ filter/ filter.pages.inc, line 310 - User page callbacks for the Filter module.
Code
function filter_format_editor_image_form_submit($form, &$form_state) {
// Determine the file either from fid (when upload is enabled) or from src
// attribute (if image upload in editor is disabled).
$file = NULL;
$fid = 0;
$attributes = $form_state['values']['attributes'] array();
if (!empty($form_state['values']['fid']) && empty($attributes['src'])) {
$file = file_load($form_state['values']['fid']);
$fid = $form_state['values']['fid'];
unset($form_state['values']['fid']);
}
elseif (!empty($attributes['src'])) {
$fid = _filter_get_file_id($attributes['src']);
if ($fid) {
$file = file_load($fid);
unset($attributes['src']);
}
}
if (!empty($file)) {
// Try to make a local path if possible for better portability.
$absolute_path = parse_url($GLOBALS['base_url'], PHP_URL_PATH) . '/';
if (empty($form_state['values']['image_style'])) {
$url = file_create_url($file->uri);
if (empty($attributes['width']) && empty($attributes['height'])) {
$attributes['width'] = $file->width;
$attributes['height'] = $file->height;
}
}
else {
$style_name = $form_state['values']['image_style'];
$style_changed = $form['image_style']['#default_value'] != $style_name;
$url = image_style_url($style_name, $file->uri);
if ($style_changed) {
$dimensions = array('width' => '', 'height' => '');
// Although the editor could determine dimensions, this would not work
// with SVG.
if (!empty($file->width)) {
$dimensions = array(
'width' => $file->width,
'height' => $file->height,
);
image_style_transform_dimensions($style_name, $dimensions);
}
$attributes['width'] = $dimensions['width'];
$attributes['height'] = $dimensions['height'];
}
elseif (empty($form_state['values']['attributes']['src']) && !empty($form_state['values']['previous_width'])) {
// Style did not change, no new file selected, previous dimensions
// exist, so re-use them. That way manually resized images with styles
// keep adapted dimensions.
$attributes['width'] = $form_state['values']['previous_width'];
$attributes['height'] = $form_state['values']['previous_height'];
}
}
$url = str_replace($GLOBALS['base_url'] . '/', $absolute_path, $url);
$attributes['src'] = $url;
$attributes['data-file-id'] = $fid;
}
$form_state['values']['attributes'] = $attributes;
}