diff --git a/includes/media.fields.inc b/includes/media.fields.inc
index 75f98e1..703ac5c 100644
--- a/includes/media.fields.inc
+++ b/includes/media.fields.inc
@@ -143,7 +143,6 @@ function media_field_widget_form(&$form, &$form_state, $field, $instance, $langc
$element += array(
'#type' => 'media', // Would like to make this a fieldset, but throws some weird warning about element_children... not sure what it is about yet.
- '#collapsed' => TRUE,
'#default_value' => $current_value,
'#required' => $instance['required'],
'#media_options' => array(
@@ -159,21 +158,57 @@ function media_field_widget_form(&$form, &$form_state, $field, $instance, $langc
),
);
+ $fields = array();
if ($field['type'] == 'file') {
- $element['display'] = array(
+ $fields['display'] = array(
'#type' => 'value',
'#value' => 1,
);
+
+ // Add the description field if enabled.
+ if (!empty($field_settings['description_field'])) {
+ $fields['description'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Description'),
+ '#value' => isset($current_value['description']) ? $current_value['description'] : '',
+ '#type' => variable_get('file_description_type', 'textfield'),
+ '#maxlength' => variable_get('file_description_length', 128),
+ '#description' => t('The description may be used as the label of the link to the file.'),
+ );
+ }
}
// Add image field specific validators.
if ($field['type'] == 'image') {
if ($field_settings['min_resolution'] || $field_settings['max_resolution']) {
- $element['#media_options']['global']['min_resolution'] = $field_settings['min_resolution'];
- $element['#media_options']['global']['max_resolution'] = $field_settings['max_resolution'];
+ $fields['media']['#media_options']['global']['min_resolution'] = $field_settings['min_resolution'];
+ $fields['media']['#media_options']['global']['max_resolution'] = $field_settings['max_resolution'];
}
+ // Add the additional alt and title fields.
+ $fields['alt'] = array(
+ '#title' => t('Alternate text'),
+ '#type' => 'textfield',
+ '#default_value' => isset($current_value['alt']) ? $current_value['alt'] : '',
+ '#description' => t('This text will be used by screen readers, search engines, or when the image cannot be loaded.
+ (Notice: this field is not fetched on -all- formatters yet. For example: If the Rendered file formatter will be used, this field is not available at the moment.)'),
+ '#maxlength' => variable_get('image_alt_length', 80),
+ '#weight' => 1,
+ '#access' => $field_settings['alt_field'],
+ );
+ $fields['title'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Title'),
+ '#default_value' => isset($current_value['title']) ? $current_value['title'] : '',
+ '#description' => t('The title is used as a tool tip when the user hovers the mouse over the image.
+ (Notice: this field is not fetched on -all- formatters yet. For example: If the Rendered file formatter will be used, this field is not available at the moment.)'),
+ '#maxlength' => variable_get('image_title_length', 500),
+ '#weight' => 2,
+ '#access' => $field_settings['title_field'],
+ );
}
+ $element += $fields;
+
return $element;
}
diff --git a/includes/media.filter.inc b/includes/media.filter.inc
index cd2a538..4e9d64c 100644
--- a/includes/media.filter.inc
+++ b/includes/media.filter.inc
@@ -180,14 +180,6 @@ function media_token_to_markup($match, $wysiwyg = FALSE) {
// Display the field elements.
$element = array();
$element['content']['file'] = media_get_file_without_label($file, $tag_info['view_mode'], $settings);
- // Overwrite or set the file #alt attribute if it has been set in this instance.
- if (!empty($element['content']['file']['#attributes']['alt'])) {
- $element['content']['file']['#alt'] = t($element['content']['file']['#attributes']['alt']);
- }
- // Overwrite or set the file #title attribute if it has been set in this instance.
- if (!empty($element['content']['file']['#attributes']['title'])) {
- $element['content']['file']['#title'] = t($element['content']['file']['#attributes']['title']);
- }
field_attach_prepare_view('file', array($file->fid => $file), $tag_info['view_mode']);
entity_prepare_view('file', array($file->fid => $file));
$element['content'] += field_attach_view('file', $file, $tag_info['view_mode']);
@@ -388,22 +380,6 @@ function media_format_form($form, $form_state, $file) {
'#default_value' => $default_view_mode
);
- if ($file->type === 'image') {
- $form['options']['alt'] = array(
- '#type' => 'textfield',
- '#title' => t('Alternate text'),
- '#description' => t('This text will be used by screen readers, search engines, or when the image cannot be loaded.'),
- '#default_value' => isset($file->field_file_image_alt_text['und'][0]['safe_value']) ? $file->field_file_image_alt_text['und'][0]['safe_value'] : '',
- );
-
- $form['options']['title'] = array(
- '#type' => 'textfield',
- '#title' => t('Title'),
- '#description' => t('The title is used as a tool tip when the user hovers the mouse over the image.'),
- '#default_value' => isset($file->field_file_image_title_text['und'][0]['safe_value']) ? $file->field_file_image_title_text['und'][0]['safe_value'] : '',
- );
- }
-
// Similar to a form_alter, but we want this to run first so that media.types.inc
// can add the fields specific to a given type (like alt tags on media).
// If implemented as an alter, this might not happen, making other alters not
diff --git a/js/wysiwyg-media.js b/js/wysiwyg-media.js
index 66ef30b..003ed88 100644
--- a/js/wysiwyg-media.js
+++ b/js/wysiwyg-media.js
@@ -171,8 +171,7 @@ InsertMedia.prototype = {
insert: function (formatted_media) {
var element = create_element(formatted_media.html, {
fid: this.mediaFile.fid,
- view_mode: formatted_media.type,
- attributes: formatted_media.options
+ view_mode: formatted_media.type
});
var markup = outerHTML(element),
diff --git a/media.module b/media.module
index b54af54..7a7a37a 100644
--- a/media.module
+++ b/media.module
@@ -463,15 +463,12 @@ function media_form_field_ui_field_edit_form_alter(&$form, &$form_state) {
if ($form['#field']['type'] == 'file' && $form['instance']['widget']['type']['#value'] == 'media_generic') {
$form['field']['settings']['display_field']['#access'] = FALSE;
$form['field']['settings']['display_default']['#access'] = FALSE;
- $form['instance']['settings']['description_field']['#access'] = FALSE;
$form['instance']['settings']['file_extensions']['#title'] = t('Allowed file extensions for uploaded files');
$form['instance']['settings']['file_extensions']['#maxlength'] = 255;
}
// On image fields using the media widget we remove the alt/title fields
if ($form['#field']['type'] == 'image' && $form['instance']['widget']['type']['#value'] == 'media_generic') {
- $form['instance']['settings']['alt_field']['#access'] = FALSE;
- $form['instance']['settings']['title_field']['#access'] = FALSE;
$form['instance']['settings']['file_extensions']['#title'] = t('Allowed file extensions for uploaded files');
// Do not increase maxlength of file extensions for image fields, since
// presumably they will not need a long list of extensions.
@@ -916,11 +913,10 @@ function media_element_process(&$element, &$form_state, $form) {
// Set some default element properties.
$element['#file'] = $file;
- $element['title'] = array(
+ $element['title-default'] = array(
'#type' => 'item',
'#title' => $element['#title'],
'#markup' => '',
- '#description' => $element['#description'],
'#required' => $element['#required'],
'#weight' => -100,
);
@@ -988,10 +984,21 @@ function media_element_process(&$element, &$form_state, $form) {
module_load_include('inc', 'media', 'includes/media.browser');
media_attach_browser_js($element);
+ $element += array(
+ '#pre_render' => array('media_pre_render_fieldset', 'form_pre_render_fieldset'),
+ );
+ $element['#theme_wrappers'] = array('fieldset');
+ if (!$element['#value']) unset($element['#value']);
+
return $element;
// @todo: make this work for file and image fields
}
+function media_pre_render_fieldset(&$v) {
+ unset($v['#value']);
+ return $v;
+}
+
/**
* Validate media form elements. The file type is validated during the upload process, but this is
* necessary in order to respect the #required property.