Drupal: theme override for Upload.module's attachments list

Update: this functionality can now be achieved with the iTweak_upload module . Thanks to Damon for the tip!

I made a custom override for Drupal 6.x’s Upload.module’s attachments table that is displayed at the bottom of a node when you create file attachments. That table is, in my opinion, one of the ugliest common and default presentations in Drupal core. Below is an example of the before and after:

Example of override

Hocus Pocus hd

To use it, unzip and drop the included folder into your active theme’s directory (e.g. /sites/default/all/garland), it should take effect without any other modifications—though you may have to reset the theme cache (goto admin/build/themes and click save without making any other changes).

Click Here to Download (shiny_upload.zip)

Return to Never Land movie

Also, I don’t know what the name is for these types of theme overrides: it’s not a module, and it’s not a whole theme. I posted this to a Drupal Group that, I think, calls them “Themer Packs“.

The icon code is based on the CCK filefield module—but the current 6.0 version is kind’ve clunky and I wanted to port it to the core Upload module. The namespace is “shiny_upload”.

Also, as an aside, the reason island94.org doesn’t currently have this enabled is because it’s still running on Drupal 5.x branch

Related posts:

  1. Social work is women's work, so we don't care Two articles came across my desk today that I think are strongly connected. The first is from Danah Boyd on...
  2. God didn't do Best Practices The best Sunday sermon I have ever heard (out of 2, the other having been when I was 8 and...


21 Responses to “Drupal: theme override for Upload.module's attachments list”

MJ on September 15th, 2008

*oops* my use of code tags didn’t work, so ignore the ‘it should read’ bit.

MJ on September 15th, 2008

This is a great bit of code. In trying to control the look of the filename, I noted that there’s a missing closing span tag on line 23 of upload_attachments.tpl.php, to close the class=file-name block. It should read:


$file_metadata = '

Many thanks for this.

Jooblie on October 10th, 2008

Whoa, this is slick.

Any way this can be made to work with 5.x? Any pointers for me to backport it?

Thanks for this!

Anonymous on October 6th, 2008

This is a great bit of code. But really didn`t make any difference. Thanks anyway

MJ on October 3rd, 2008

How could us alter this code to open the associated link in a new browser window?

Anthony on October 24th, 2008

Hi,

Thanks very much for this! It works fine in 5.x with the Zen theme. To get it to work, I madea few minor amendments.

1. Add the following to your template.php

function phptemplate_upload_attachments($files) {
return _phptemplate_callback('upload_attachments', array('files' => $files));
}

2. Place upload_attachments.tpl.php, shiny_upload.css, and the file-icons folder in the same directory level as template.php

3. In the function _shiny_upload_create_icon_path, I used path_to_subtheme

$iconpath = path_to_subtheme()
.'/file-icons/'. $theme .'/16x16/mimetypes/'. $iconname .'.png';

Hope this helps!

qrta on January 6th, 2009

MB, the search function produces the same message for me, so you are not alone :( and I don’t know the solution. But someone maybe hears us…

MB on December 26th, 2008

This module doesn’t work with the Drupal Search function.

I used it in Drupal 6.X. However whenever the search results in more than two documents which match the keyword, I get a fatal error:

PHP Fatal error: Cannot redeclare shiny_upload_upload_attachments() (previously declared in /var/site_XXX/sites/all/themes/marinelli/shiny_upload/upload_attachments.tpl.php:14) in /var/site_XXX/sites/all/themes/marinelli/shiny_upload/upload_attachments.tpl.php on line 33, referer: http://www.XXX.com/

I like what the module does and it works on views, home page etc where the nodes are listed in some form of list, but I think the search functionality is very important and that is leading to multiple inclusion of the function. For example, as a test I made the following change in theme.inc:

function theme_render_template($template_file, $variables) {
extract($variables, EXTR_SKIP); // Extract the variables to a local namespace
ob_start(); // Start output buffering
include_once “./$template_file”; // Include the template file —> CHANGED include to include_once
$contents = ob_get_contents(); // Get the contents of the buffer
ob_end_clean(); // End buffering and discard
return $contents; // Return the contents
}

Then the search results started to work, but the views were returning only one single node.

Any fixes for the redeclaration issue?

Leonard on August 24th, 2008

wow, what a difference! thx a lot for this hack.

jo wouters on August 31st, 2008

Although it’s a little bit bigger then the usual snippet; you could add it to the Drupal handbook on the Theme Snippets page (http://drupal.org/node/45471) ?

Thanks! These kind of small changes can make a use difference to the looks of a site.

Danny J on November 14th, 2008

Very Very Useful. Thanks a lot.

klandon on November 29th, 2008

Thank you, this is a great improvement.

I do have one problem, however — my site won’t show the icons. My themes, however, are not in the sites/default/all/ folder, and I’m wonder if this might be my problem?

Guix on December 8th, 2008

Thanks for this ! However it’s generating problems with the cron : it’s printing the

and it’s content. Do you have this too ?
Roel De Meester on December 10th, 2008

This ‘module’ gives problems when running cron.
I haven’t investigated further but i guess it has to do with the print shiny_upload_upload_attachments($files);
which is on top of the upload_attachments.tpl.php file.

I’ll investigate further and report back..

Roel De Meester on December 12th, 2008

Crossposting..

See http://groups.drupal.org/node/13873#comment-59812 for my comment.
Grab the fix on http://krimson.be/en/shiny-upload-almost-converted-a-module

@island94: Are you interesting in commiting your code into a proper drupal project, PM me if you need help.

qrta on January 10th, 2009

I have solved the problem:
you have to move the function declarations into one other file, good place is for example into one custom module. The upload_attachments.tpl.php only contains the print and drupal_add_css invocations.

jamie on April 25th, 2009

In additional change for this code to work with Drupal 5, the l() function which reads:

$file_link = ”. l(shiny_upload_file_icon($file) . $text, $file_url, array(‘html’=>’true’)) . ”;

Should be changed to:

$file_link = ”. l(shiny_upload_file_icon($file) . $text, $file_url, array(), null, null, false, true) . ”;

Andrew on May 27th, 2009

I love it. Thanks.

Evgeny Pavlov on June 13th, 2009

If you have an issue with Search Module, you can move functions (as mentioned qrta) into template.php.

s on June 25th, 2009

fYI if you are using “Garland” theme and have specified custom colors using the color picker you must physically delete the cached Garland theme at sites/default/files/color/garland-xxxxx

Then you must configure and save your theme to reset this cache. Note that garland “color picker” doesn’t work if your file method is Private.

If you are using private file method and Garland and have lots of files I do not suggest you attempt to use this file icon hack at all or you risk changing file paths for all your attachments.

damon on August 17th, 2009

I used the iTweak Upload (http://drupal.org/project/itweak_upload) module and it works great!

Leave a Reply

(required)

(required)