diff --git a/includes/media.filter.inc b/includes/media.filter.inc index 64b72a3..8d38622 100644 --- a/includes/media.filter.inc +++ b/includes/media.filter.inc @@ -683,6 +683,53 @@ function media_get_file_without_label($file, $view_mode, $settings = array()) { } } + // Respect the width/height set in WYSIWYG editors by ensuring that all + // attributes and styles use the same values. + $height = $width = FALSE; + + // The logic goes: + // 1) Check to see if the user manually entered a style into the html or tinymce. + // 2) If not, use the height and width attributes. + // 3) If those aren't set, revert to the height and width that were already saved. + if (isset($settings['width']) || isset($settings['height'])) { + $width = isset($settings['width']) ? $settings['width'] : FALSE; + $height = isset($settings['height']) ? $settings['height'] : FALSE; + } + elseif (isset($settings['attributes']['width']) || isset($settings['attributes']['height'])) { + $width = isset($settings['attributes']['width']) ? $settings['attributes']['width'] : FALSE; + $height = isset($settings['attributes']['height']) ? $settings['attributes']['height'] : FALSE; + } + elseif (isset($element['#attributes'])) { + $width = isset($element['#attributes']['width']) ? $element['#attributes']['width'] : FALSE; + $height = isset($element['#attributes']['height']) ? $element['#attributes']['height'] : FALSE; + } + + if ($width && $height) { + $element['#height'] = $height; + $element['#width'] = $width; + + if (!isset($settings['wysiwyg'])) { + $existing_styles = isset($element['#attributes']['style']) ? media_parse_css_declarations($element['#attributes']['style']) : array(); + $existing_styles['height'] = $height . 'px'; + $existing_styles['width'] = $width . 'px'; + $styles = array(); + + foreach ($existing_styles as $style_name => $style_value) { + $styles[] = $style_name . ":" . $style_value; + } + + $element['#attributes']['style'] = implode(';', $styles); + + // Special handling for image_formatter theme function + // TODO: Can we do this better? + if ($element['#theme'] == 'image_formatter' && isset($element['#item'])) { + $element['#item']['width'] = $width; + $element['#item']['height'] = $height; + $element['#item']['attributes'] = $element['#attributes']; + } + } + } + return $element; }