function template_preprocess_file_entity in File Entity (fieldable files) 7.2
Same name and namespace in other branches
- 7.3 file_entity.module \template_preprocess_file_entity()
- 7 file_entity.module \template_preprocess_file_entity()
Process variables for file_entity.tpl.php
The $variables array contains the following arguments:
- $file
- $view_mode
See also
File
- ./
file_entity.module, line 1519 - Extends Drupal file entities to be fieldable and viewable.
Code
function template_preprocess_file_entity(&$variables) {
$view_mode = $variables['view_mode'] = $variables['elements']['#view_mode'];
$variables['file'] = $variables['elements']['#file'];
$file = $variables['file'];
$variables['id'] = drupal_html_id('file-' . $file->fid);
$variables['date'] = format_date($file->timestamp);
$account = user_load($file->uid);
$variables['name'] = theme('username', array(
'account' => $account,
));
$uri = entity_uri('file', $file);
$variables['file_url'] = url($uri['path'], $uri['options']);
$label = entity_label('file', $file);
$variables['label'] = check_plain($label);
$variables['page'] = $view_mode == 'full' && file_entity_is_page($file);
// Hide the file name from being displayed until we can figure out a better
// way to control this. We cannot simply not output the title since
// contextual links require $title_suffix to be output in the template.
// @see http://drupal.org/node/1245266
if (!$variables['page']) {
$variables['title_attributes_array']['class'][] = 'element-invisible';
}
// Flatten the file object's member fields.
$variables = array_merge((array) $file, $variables);
// Helpful $content variable for templates.
$variables += array(
'content' => array(),
);
foreach (element_children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
// Make the field variables available with the appropriate language.
field_attach_preprocess('file', $file, $variables['content'], $variables);
// Attach the file object to the content element.
$variables['content']['file']['#file'] = $file;
// Display post information only on certain file types.
if (variable_get('file_submitted_' . $file->type, FALSE)) {
$variables['display_submitted'] = TRUE;
$variables['submitted'] = t('Uploaded by !username on !datetime', array(
'!username' => $variables['name'],
'!datetime' => $variables['date'],
));
$variables['user_picture'] = theme_get_setting('toggle_file_user_picture') ? theme('user_picture', array(
'account' => $account,
)) : '';
}
else {
$variables['display_submitted'] = FALSE;
$variables['submitted'] = '';
$variables['user_picture'] = '';
}
// Gather file classes.
$variables['classes_array'][] = drupal_html_class('file-' . $file->type);
$variables['classes_array'][] = drupal_html_class('file-' . $file->filemime);
if ($file->status != FILE_STATUS_PERMANENT) {
$variables['classes_array'][] = 'file-temporary';
}
// Change the 'file-entity' class into 'file'
if ($variables['classes_array'][0] == 'file-entity') {
$variables['classes_array'][0] = 'file';
}
// Clean up name so there are no underscores.
$variables['theme_hook_suggestions'][] = 'file__' . $file->type;
$variables['theme_hook_suggestions'][] = 'file__' . $file->type . '__' . $view_mode;
$variables['theme_hook_suggestions'][] = 'file__' . str_replace(array(
'/',
'-',
), array(
'__',
'_',
), $file->filemime);
$variables['theme_hook_suggestions'][] = 'file__' . str_replace(array(
'/',
'-',
), array(
'__',
'_',
), $file->filemime) . '__' . $view_mode;
$variables['theme_hook_suggestions'][] = 'file__' . $file->fid;
$variables['theme_hook_suggestions'][] = 'file__' . $file->fid . '__' . $view_mode;
}