function file_view_multiple in File Entity (fieldable files) 7.3
Same name and namespace in other branches
- 7 file_entity.file_api.inc \file_view_multiple()
- 7.2 file_entity.file_api.inc \file_view_multiple()
Construct a drupal_render() style array from an array of loaded files.
Parameters
array $files: An array of files as returned by file_load_multiple().
string $view_mode: View mode.
int $weight: An integer representing the weight of the first file in the list.
string $langcode: A string indicating the language field values are to be shown in. If no language is provided the current content language is used.
Return value
array An array in the format expected by drupal_render().
1 call to file_view_multiple()
- file_entity_metadata_view_file in ./
file_entity.module - Entity API callback to view files.
File
- ./
file_entity.file_api.inc, line 77 - API extensions of Drupal core's file.inc.
Code
function file_view_multiple($files, $view_mode = 'full', $weight = 0, $langcode = NULL) {
$build = array();
if (empty($files)) {
return $build;
}
$entities_by_view_mode = entity_view_mode_prepare('file', $files, $view_mode, $langcode);
foreach ($entities_by_view_mode as $entity_view_mode => $entities) {
field_attach_prepare_view('file', $entities, $entity_view_mode, $langcode);
entity_prepare_view('file', $entities, $langcode);
foreach ($entities as $entity) {
$build['files'][$entity->fid] = file_view($entity, $entity_view_mode, $langcode);
}
}
foreach ($files as $file) {
$build['files'][$file->fid]['#weight'] = $weight;
$weight++;
}
// Sort here, to preserve the input order of the entities that were passed to
// this function.
uasort($build['files'], 'element_sort');
$build['files']['#sorted'] = TRUE;
return $build;
}