In my module drupal.org/project/pdf I declared
pdf_field_formatter_info()
pdf_field_formatter_view()
to display PDF for file_field.

function pdf_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
switch ($display['type']) {
case 'pdf_default':
foreach ($items as $delta => $item) {
$element[$delta] = array(
'#theme' => 'pdf_formatter_default',
'#file' => $item,
);
}
break;
case 'pdf_thumbnail':
foreach ($items as $delta => $item) {
$element[$delta] = array(
'#theme' => 'pdf_formatter_thumbnail',
'#file' => $item,
);
}
break;
}
return $element;
}

When I use my owned theme_pdf_formatter_thumbnail($variables) in file_entity. I can't pass the $variables to theme function.
Do I need to use API in file_entity to re-use field_formatter?

I get the returned $element from the hook_field_formatter_view like this
Array
(
[0] => Array
(
[#theme] => pdf_formatter_thumbnail
[#file] => Array
(
[fid] => 8
[uid] => 1
[filename] => arial_unicode_en_cidfont.pdf
[uri] => public://arial_unicode_en_cidfont.pdf
[filemime] => application/pdf
[filesize] => 15779
[status] => 1
[timestamp] => 1329144740
[type] => application
[content] => Array
(
)

)

)

)

But the $variable in the theme function like this

Array
(
[file] =>
)

Comments

devin carlson’s picture

Status: Active » Closed (fixed)

Any standard file formatter should be compatible with File entity and shouldn't require implementing any additional File entity API hooks.

That said, I'd suggest looking at Media provider modules (Media: YouTube, Media: Vimeo) for examples of file formatters used with File entity.