|
<?php |
|
|
|
// Render a file using the 'Generic file' formatter (a nice link with an icon): |
|
$file = file_load(1); |
|
$field = array('type' => 'file'); |
|
// File fields are stupid with their field values. |
|
$items = array(0 => array('fid' => $file->fid) + (array) $file); |
|
$display = array('type' => 'file_default'); |
|
$output = field_items_render($field, array(), $items, $display); |
|
return drupal_render($output); |
|
|
|
function field_items_render(array $field, array $instance, array $items, array $display, $langcode = LANGUAGE_NONE) { |
|
$field += field_info_field_types($field['type']); |
|
|
|
$display += field_info_formatter_types($display['type']); |
|
|
|
$instance += array( |
|
'entity_type' => 'node', |
|
'bundle' => '_fake', |
|
'settings' => array(), |
|
); |
|
$instance['settings'] += $field['instance_settings']; |
|
|
|
$entity_type = 'node'; |
|
$entity = NULL; |
|
$entities = array(0 => $entity); |
|
$entity_items = array(0 => &$items); |
|
|
|
// Run hook_field_prepare_view() on the field module. |
|
$function = $field['module'] . '_field_prepare_view'; |
|
if (function_exists($function)) { |
|
$function($entity_type, $entities, $field, $instances, $langcode, $entity_items); |
|
} |
|
|
|
// Run hook_field_formatter_prepare_view() on the formatter module. |
|
$function = $display['module'] . '_field_formatter_prepare_view'; |
|
if (function_exists($function)) { |
|
$function($entity_type, $entities, $field, array(0 => $instance), $langcode, $entity_items, array(0 => $display)); |
|
} |
|
|
|
// Run hook_field_formatter_View() on the formatter module. |
|
$function = $display['module'] . '_field_formatter_view'; |
|
$result = $function($entity_type, NULL, $field, $instance, $langcode, $items, $display); |
|
|
|
return $result; |
|
} |