diff --git a/media.filter.inc b/media.filter.inc
index aec8abe..bda9549 100644
--- a/media.filter.inc
+++ b/media.filter.inc
@@ -170,8 +170,7 @@ function media_token_to_markup($match, $wysiwyg = FALSE) {
return '';
}
- $file_field = media_get_file_without_label($media_obj, $media['view_mode'], $settings);
- return drupal_render($file_field);
+ return theme('media_file', field_attach_view('media', $media_obj, $media['view_mode'], null));
}
/**
diff --git a/media.module b/media.module
index 807924e..f3087ba 100644
--- a/media.module
+++ b/media.module
@@ -344,6 +344,10 @@ function media_theme() {
'variables' => array('file' => NULL),
'file' => 'media.theme.inc',
),
+ // Showing one element
+ 'media_file' => array(
+ 'variables' => array('element' => NULL),
+ ),
);
}
diff --git a/media.theme.inc b/media.theme.inc
index 1b5f373..d785453 100644
--- a/media.theme.inc
+++ b/media.theme.inc
@@ -8,6 +8,23 @@
*/
/**
+ * Display a media file.
+ * @param array $element
+ * The form element.
+ * @return string
+ */
+function theme_media_file($element) {
+ // Add the CSS classes.
+ $classes = array(
+ 'media', 'file', $element['file']['#view_mode']
+ );
+ // Add the CSS for our display.
+ $output = '
' . drupal_render($element) . '
';
+
+ return $output;
+}
+
+/**
* Display the media file browser.
* @TODO this is depreciated I think
* @param array $element
diff --git a/media.types.inc b/media.types.inc
index 8f7a813..9dcd2de 100644
--- a/media.types.inc
+++ b/media.types.inc
@@ -256,14 +256,36 @@ function media_is_type($media, $args) {
function media_media_format_form_prepare_alter(&$form, &$form_state, $media) {
switch($media->type) {
case 'image':
- // @TODO: Isn't there a $file->description?
- $description = $media->filename;
- $form['options']['alt'] = array(
- '#type' => 'textfield',
- '#title' => t('Description'),
- '#default_value' => $description,
- '#description' => t('Alternate text a user will see if the image is not available'),
- );
+
+ // Adding custom fields
+ $result = db_query('SELECT * FROM {field_config_instance} WHERE bundle = :bundle', array(':bundle'=> $media->type));
+ foreach ($result as $record) {
+
+ // Do not print a form field for a file.
+ if ($record->field_name == 'file') {
+ continue;
+ }
+
+ // Registered value.
+ // @TODO: Find a better way of showing the registered value.
+ $value = (count($media->{$record->field_name}) > 0) ? $media->{$record->field_name}['und'][0]['value'] : '';
+
+ // Widget
+ $data = unserialize($record->data);
+ switch ($data['widget']['type']) {
+ case 'text_textfield':
+ $type = 'textfield';
+ break;
+ }
+
+ $form['options'][$record->field_name] = array(
+ '#type' => $type,
+ '#title' => t($data['label']),
+ '#description' => t($data['description']),
+ '#value' => $value,
+ );
+ }
+
break;
}
}