1.20.x file.module file_view_multiple($files, $view_mode = 'full', $weight = 0, $langcode = NULL)

End of "defgroup file_access".

Construct a backdrop_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 backdrop_render().

Related topics

File

modules/file/file.module, line 3256
Defines a "managed_file" Form API field and a "file" field for Field module.

Code

function file_view_multiple($files, $view_mode = 'full', $weight = 0, $langcode = NULL) {
  $build = array();

  $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;
}