Commit f6aa1731 authored by emerham's avatar emerham Committed by joseph.olstad

Issue #2883529 by emerham: Linking Issues - related to 2881204

parent a757f948
......@@ -97,7 +97,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');
}
......@@ -167,7 +166,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));
......
......@@ -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) {
......
......@@ -299,7 +299,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);
}
......@@ -351,8 +351,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
......
......@@ -389,7 +389,7 @@ function media_wysiwyg_allowed_attributes() {
'data-delta',
));
drupal_alter('media_wysiwyg_allowed_attributes', $allowed_attributes);
return $allowed_attributes;
return $allowed_attributes;
}
/**
......@@ -603,7 +603,7 @@ function media_wysiwyg_form_file_entity_file_type_form_alter(&$form, &$form_stat
if (empty($form_state['build_info']['args'][0])) {
return;
}
$options = array();
// Add an option allowing users not to use a view mode.
......
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