1 file.module | template_preprocess_file_entity(&$variables) |
Process variables for file.tpl.php
The $variables array contains the following arguments:
- $file
- $view_mode
See also
File
- core/
modules/ file/ file.module, line 924 - Defines a "managed_file" Form API field and a "file" field for Field module.
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'] = backdrop_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_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']['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;
// Gather file classes.
$variables['classes'][] = backdrop_html_class('file-' . $file->type);
if ($file->status != FILE_STATUS_PERMANENT) {
$variables['classes'][] = 'file-temporary';
}
// Change the 'file-entity' class into 'file'
if ($variables['classes'][0] == 'file-entity') {
$variables['classes'][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;
}