Tags/topics: 
1
Answers
Vote up!
0
Vote down!

How To Format Table of Files Field On Product Variation Display?

We have a Commerce Product Display. In the Product Variation is a field of type File which is for links to various PDF documents. The display format is 'table of files'. It works, however it looks clunky.

I'm having trouble locating the tpl or inc file that controls formatting for this table. We don't want to globally change table display, we just want to alter it on this one Display.

Where is the php located to theme this? Or is there a function I need to add to my theme to hook into that display?

Specifically, we want to: 1. Get rid of the header and 2. Get rid of the file size column

Asked by: suntower
on September 5, 2014

1 Answer

Vote up!
1
Vote down!

This question has nothing to do with Commerce. But as you're a regular, here's a freebie:

https://www.drupal.org/project/extended_file_field

That module extends the table with options that should make you happy.

Or if you want to use a bit of code...

<?php
// an example which adds upload date.
function MYTHEME_file_formatter_table($variables) {
 
$header = array(t('Attachment'), t('Size'),t('Upload Date'));
 
$rows = array();
  foreach (
$variables['items'] as $delta => $item) {
    if (
$item['timestamp'] == 0) {
     
$item['timestamp'] = 1234567890//or whatever you want for the default date
   
}
   
$rows[] = array(
     
theme('file_link', array('file' => (object) $item)),
     
format_size($item['filesize']),
     
format_date($item['timestamp'],'custom','m/d/Y'),
    );
  }
 
asort($rows);
  return empty(
$rows) ? '' : theme('table', array('header' => $header, 'rows' => $rows));
}
?>

See this function in the API.

Josh Miller
Answer by: Josh Miller
Posted: Sep 18, 2014