diff --git a/modules/media_wysiwyg/includes/media_wysiwyg.filter.inc b/modules/media_wysiwyg/includes/media_wysiwyg.filter.inc index 25cee6bb05ab2e82dd981fb80a12a21b20d1fd90..1cd6a50ed64cda47af30ed6b7d2a10e7e8575b2c 100644 --- a/modules/media_wysiwyg/includes/media_wysiwyg.filter.inc +++ b/modules/media_wysiwyg/includes/media_wysiwyg.filter.inc @@ -146,7 +146,6 @@ function media_wysiwyg_token_to_markup($match, $wysiwyg = FALSE, $langcode = NUL } $tag_info = drupal_json_decode($tag); - if (!isset($tag_info['fid'])) { throw new Exception('No file Id'); } @@ -216,7 +215,9 @@ function media_wysiwyg_token_to_markup($match, $wysiwyg = FALSE, $langcode = NUL $attribute_whitelist = media_wysiwyg_allowed_attributes(); $settings['attributes'] = array_intersect_key($attributes, array_flip($attribute_whitelist)); $settings['fields'] = $fields; - + if (isset($tag_info['fields']['external_url'])) { + $settings['fields']['external_url'] = $tag_info['fields']['external_url']; + } if (!empty($tag_info['attributes']) && is_array($tag_info['attributes'])) { $settings['attributes'] = array_intersect_key($tag_info['attributes'], array_flip($attribute_whitelist)); diff --git a/modules/media_wysiwyg/includes/media_wysiwyg.pages.inc b/modules/media_wysiwyg/includes/media_wysiwyg.pages.inc index 41e4430cbea65d9d460abb174bc5e401ff56be7e..ad291670622d8dc6daf13f4474bbcb9db8e4ca98 100644 --- a/modules/media_wysiwyg/includes/media_wysiwyg.pages.inc +++ b/modules/media_wysiwyg/includes/media_wysiwyg.pages.inc @@ -104,12 +104,20 @@ function media_wysiwyg_format_form($form, &$form_state, $file) { '#default_value' => $align_default, ); } - // Add fields from the file, so that we can override them if necessary. $form['options']['fields'] = array(); foreach ($fields as $field_name => $field_value) { $file->{$field_name} = $field_value; } + // Get the external url from the fid array. + $external_url = empty($query_fields['external_url']) ? NULL : $query_fields['external_url']; + // Field to attach external url's to files for linking. + $form['options']['external_url'] = array( + '#type' => 'textfield', + '#title' => t('Link Image'), + '#description' => t('Enter a URL to turn the image into a link.'), + '#default_value' => $external_url, + ); field_attach_form('file', $file, $form['options']['fields'], $form_state); $instance = field_info_instances('file', $file->type); foreach ($instance as $field_name => $field_value) { diff --git a/modules/media_wysiwyg/js/media_wysiwyg.filter.js b/modules/media_wysiwyg/js/media_wysiwyg.filter.js index f3df9363cf5e3537933089d1b1ed4f2c6ad57bca..ca8ba7a2eb9b2eca44c092f09a4f14de9288a089 100644 --- a/modules/media_wysiwyg/js/media_wysiwyg.filter.js +++ b/modules/media_wysiwyg/js/media_wysiwyg.filter.js @@ -300,7 +300,7 @@ // Attempt to override the link_title if the user has chosen to do this. info.link_text = this.overrideLinkTitle(info); // Apply link_text if present. - if (info.link_text) { + if ((info.link_text) && (info.fields.external_url.length === 0)) { $('a', element).html(info.link_text); } @@ -352,8 +352,7 @@ }); // Extract the link text, if there is any. - file_info.link_text = (Drupal.settings.mediaDoLinkText) ? element.find('a').html() : false; - + file_info.link_text = (Drupal.settings.mediaDoLinkText) ? element.find('a:not(:has(img))').html() : false; // When a file is embedded, its fields can be overridden. To allow for // the edge case where the same file is embedded multiple times with // different field overrides, we look for a data-delta attribute on