Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I just came across this icon set today: http://www.splitbrain.org/projects/file_icons
Wondering if it would be a better alternative to what's used now and or they could be used in addition? Seems like there are more and more specific icons.
Comment | File | Size | Author |
---|---|---|---|
#8 | filefield_icon_sets.patch | 3.73 KB | quicksketch |
Comments
Comment #1
brian_c CreditAttribution: brian_c commentedThis is fantastic, thanks.
One big problem with filefield's current default icons is they are PNG24's with alpha channel, which look bad in IE6 unless you use some sort of PNGfix technique... which IMHO is a poor solution for the default icon set. These alternate icons are PNG8 so there's no problem with them. They also look closer to standard Windows icons which I think will be more recognizable to the majority of users.
We've copied these into an "images/fileicons" folder in our theme directory, and are using them by way of the following code in our template.php file:
(Edit: I've fixed a typo and incorporated use of $base_url as mentioned in #5 below)
Just change MYTHEME to the name of your theme (and change '/images/fileicons/' if you're storing them somewhere else).
Please note that this uses simple filename extension matching to determine the icon to use, instead of mime-type like filefield's default implementation. This was sufficient for our purposes and will probably be easier for the client to understand if they want to replace any. That being said, it would be straightforward to extend this to check the $file array's mimetype key and use that instead, but you'd have to write a big mapping table. :)
Hope this helps someone.
Comment #2
brian_c CreditAttribution: brian_c commentedComment #3
quicksketchYeah the current way icon sets are set up is sub-optimal. Right now it's practically required to place the icons inside of the FileField module, when it should just be a variable that let's you place the icons anywhere you want as long as they're named properly. I'd be happy to fix this limitation, but I'm not sure how necessary it is to include multiple sets of icons within FileField by default.
Comment #4
brian_c CreditAttribution: brian_c commentedI'd humbly offer two suggestions:
1) As you mentioned, add a textfield in Filefield settings to allow user to specify path to custom icon set, then a non-technical user should be able to replace them by just using the correct filenames
2) Add a theming hook to allow themers to override JUST the function which provides the URL for the icon, given the $file array. This would allow unlimited flexibility for more advanced users, and means they don't have to duplicate the module's output markup like I've done above.
Cheers
Comment #5
dogbertdp CreditAttribution: dogbertdp commentedbrian_c,
Thanks for the code snippet and path. While it's dependent on a file extension, and that may bother some, I think it rather efficient and simple.
That said I couldn't get it to work without a couple of changes. Here is the code I ended up putting in my template.php with comments explaining the changes I made and why (as usually, anyone else using this code should exclude the opening
"<?php" and closing "?>"
):Thanks for the help,
Mike Hays
Comment #6
brian_c CreditAttribution: brian_c commentedGood point, I forgot that the site I wrote this code for used a <BASE> tag, eliminating the need for us to use $base_url.
Comment #7
srobert72 CreditAttribution: srobert72 commentedSubscribe
Comment #8
quicksketchI'm moving the topic of this issue to a new direction. Because we're not going to add multiple icon sets to FileField directly, we should provide the ability to have icon packs be provided by other modules. The D7 file.module already provides this functionality through a variable (see http://api.lullabot.com/file_icon_path/7). Unfortunately in D6 we have named themes (maybe that's actually a good thing) not icon directories. To maintain existing API compatibility in D6, we need to keep this $theme concept but allow other modules to provide a file icon set directory. This patch allows this through hook_filefield_icon_sets().
Comment #9
quicksketchI've committed this patch and it will be in 3.6.
Comment #10
nemchenk CreditAttribution: nemchenk commentedAm I being daft, or can this only be done by implementing hook_filefield_icon_sets() in a module? Can this be done in template.php?
Comment #11
quicksketchProviding options to switch icons and multiple icon sets can only be provided by modules. However you can (and always have been able to) override the display of all FileField icons by overriding theme_filefield_icon().
Comment #13
cluke009 CreditAttribution: cluke009 commentedI had issues with both of the above solutions and wrote some new code. This seems a little simpler to me as it only needs to override 1 function.
This just points to my images directory and uses the mimetype as the filename.
ie: application-pdf, application-msword