Hi all,
I'm trying to obtain a simple result on a view related to fielfields, but I can't find a simple solution.
I want to show a view table with the list of files attached to a node (attached using filefield). I can insert in this table every information related to the file (name, size, mimetype, data uploas, description, ...) but I can't show the icon for this file (and I think this is a quite natural thing).
I have searched for an answer on issues, but I have found nothing related to a view.
Someone can explain if this thing is possible, and if the answer is positively, how?
Thanks a lot,
Saxx
Comment | File | Size | Author |
---|---|---|---|
#28 | filefield_icon_views.patch | 1.84 KB | quicksketch |
#26 | snapshot5.png | 33.54 KB | php5engineer |
Comments
Comment #1
quicksketchSounds like you've created a relationship for "File: Name of your field" to the files table, which is getting you all the meta information (name, size, mimetype, etc.) which is great. If you want to output the name of the file with the nice little icon that comes with FileField, then don't use the "File: Filename" field, instead use "Content: Name of your field (field_name)", so that CCK outputs the filename after running it through the formatter.
Comment #2
SaxxIng CreditAttribution: SaxxIng commentedYes, it's right!
But I need to represent only the icon on my table (on a separate column respect to file_name). For example (headers of hypothetically table):
icon | mime_type | file_name | file_description | file_size | node_links
Generally this is a quite usual thing on many sites.
Do you think this is possible with the actually file_field fields (and integration with views)? If no, do you think this can be a reasonable feature request?
Thanks a lot for the rapid answer and for the great module.
Regards,
Saxx
Comment #3
quicksketchThis looks like something that could be possible, since the theme_filefield_icon() is solely responsible for outputting a file icon. However the FileField Views implementation does not add this particular support, so we should move this to a feature request. Note I don't have any timeline or plans to implement this myself, but I could see it as a valuable feature which I'd be happy to include if developed.
Comment #4
Golem07 CreditAttribution: Golem07 commentedVery good feature request.
Comment #5
xjmTracking.
Comment #6
mattiasj CreditAttribution: mattiasj commentedsubscribing
Comment #7
czeky CreditAttribution: czeky commentedYeah, to display just an clickable icon would be great, I'm need this as well
Comment #8
xjmAlright, I spent four hours trying to add a field handler to filefield that would do this, but it just wasn't working. My views-fu is not good enough, it appears. However, I think I'm onto how to do this in the theming layer using filefield's theming includes:
views-view-field--filemime.tpl.php
. See http://www.group42.ca/theming_views_2_the_basics for help deciding what to name the file.)Ta-da! You might want to do more with the markup or CSS (e.g. add a link around
$icon
to make it clickable), but this should get you started.Comment #9
boabjohn CreditAttribution: boabjohn commented@xjm : mate you totally rock! This little fix works a treat and addresses a need I've spent days trying to figure out with no tech skills at all :-{)
BUT: My view comes up WITH nice icons, but NOT LINKED to the file download.
As I see it, this should be covered by the Views option to "Link this field to download the file", which I have ticked.
I note your code above just says to print $icon, and assume Views should be doing the rest... but for me, this doesn't happen.
The
Any clue what I could be missing here? What else can I provide to help troubleshoot?
Comment #10
xjmSince we're overriding the output of the field, we need to add the link back to the overridden output, too. If you check Link this field to download the file on the mimetype field, then it looks like the path to the file will be in the variable
$row->{$field->aliases['filepath']}
in the template file. So, instead ofprint $icon
in the template above, you'd need to do something like:This should render an HTML link to the file around the image.
Comment #11
boabjohn CreditAttribution: boabjohn commentedThanks heaps. Marking this reviewed.
Comment #12
quicksketchAs a "feature request" this isn't suitable to be included in FileField. While it's nice to have as documentation, the intention was to make accessing the icon alone possible directly through Views, without any theming. So I'm setting this back to active because there isn't any code that can be applied to the FileField project yet.
Comment #13
boabjohn CreditAttribution: boabjohn commentedSorry quicksketch, still new to issue protocols.
@xjm: the template actually isn't working for me. My view prints out the text: "application/pdf" and the text is not linked.
The template file is:
The view appears to know about the template (ie, it appears in the Theme Information listing)
All caches and browsers flushed
There are no strange entries in Watchdog
The icons actually exist at: /sites/all/modules/filefield/icons/protocons/16x16/mimetypes/application-pdf.png
Is there some diagnostic I can use to trace the problem?
Comment #14
xjmThe template is coded to print the icon only if it can locate the theme file and the mimetype is set (
if
statement), and to use the view's default output otherwise (else
statement). So, you could do some basic PHP troubleshooting to see what's happening and what the variables contain. You can putprint $variable;
at any point in the code to see what the value of the variable
$variable
is, or even something likeprint "Got to this step.";
to see what branch of the code you're in. (It will be printed in the field in your view during your troubleshooting.)
Edit: The article I linked above (http://www.group42.ca/theming_views_2_the_basics) has some more generalized help for developing theming templates.
Regarding #12, for anyone who's interested, the logic could just as easily be used in a field handler (switch "print" for "return," etc.); I just couldn't figure out how to cleanly add a second handler for the file mimetype that depended on the filefield relationship. So, if someone figures out how to do that, I could roll a patch.
Comment #15
czeky CreditAttribution: czeky commentedHi, for me it seems to be working! except the link contain translation code in the link
http://www.xy.com/en/sites/default/files/poster.pdf
and should be... (without language code /en)
http://www.xy.com/sites/default/files/poster.pdf
any ideas?
also, when there are more files in the list, the are not displayed
but anyway good way
Comment #16
xjmAye, I assumed there was only one file; the code would need to be modified to support multiple values on the filefield. Not sure exactly how without looking into it more.
Regarding the lanugage prefix being added... that seems to be added by the l() or url() API functions. Both of these call language_url_rewrite() which does some funny business with the path based on language configuration.
Reflecting, I think maybe it should use file_create_url() instead, replacing:
with something like:
If that doesn't work, as a (hackish) workaround, you could try manually coding your URL:
Comment #17
czeky CreditAttribution: czeky commentedfirst code gives views AJAX error "An error occurred at /cs/admin/build/views/ajax/preview/media." The actual page is blank, second code works
Comment #18
xjmSorry, I made a typo. It should have read:
$file_url = file_create_url($row->{$field->aliases['filepath']});
I'll fix it in the post above for anyone else who wishes to test it.
Comment #19
jmuessig CreditAttribution: jmuessig commentedsubscribe
Comment #20
Vasu CreditAttribution: Vasu commentedsubscribing
Comment #21
Cyberwolf CreditAttribution: Cyberwolf commentedSubscribing.
Comment #22
Cyberwolf CreditAttribution: Cyberwolf commentedI believe the right way to solve this is simply adding a new filefield field formatter that only displays the icon.
Comment #23
xjmThere is also a patch that allows another workaround:
#718832: Add file extension as a field available within the File group
You'd "rewrite output of this field" with the file extension to render the icon with markup or CSS as appropriate.
Comment #24
quicksketchI think a better option would be to create a Views handler. Not many people want to show just the icon without a label of any sort anywhere else. I imagine this scenario really only comes up when people want to put the icon in its own table cell or something.
Comment #25
grasmash CreditAttribution: grasmash commentedI just use Views PHP Customfield to grab file information:
Comment #26
php5engineer CreditAttribution: php5engineer commentedIn most basic case where are no need for any additional module or php code. See a configuration of a views field on the attached picture
Comment #27
xjm#26: Your configuration does not provide the filefield icons appropriate to the file types.
Comment #28
quicksketchI've added this new Views handler for pulling in a file icon based on its MIME type. Note that this is only available if you've added a relationship over to the files table (usually by adding a "Content: Name of filefield" relationship to your view). Then a new field called "File: Icon" will be available. Since file icons don't require any actual FileField information, this handler will work on all files, including ones not uploaded by FileField. FileField just so happens to have a nice collection of icons that would be suitable for providing this option.
Comment #30
AdrianB CreditAttribution: AdrianB commentedIf anyone using Drupal 7 finds quicksketch's comment #28 above and wonder how to do this in Drupal 7: There is no "File: Icon" field, instead, add a "File: Mime type" field and then check the checkbox Display an icon representing the file type, instead of the MIME text (such as "image/jpeg").
Comment #31
cduwe CreditAttribution: cduwe commentedWhat module provides the "File: Mime type" field to views? I don't seem to have that option.
Comment #32
szt CreditAttribution: szt commented@cduwe: you must start the view-creation process with "Files" (not with "Content") at admin/structure/views/add.
Comment #33
ice5nake CreditAttribution: ice5nake commentedI kind of wish that an empty file relationship would not display an icon. I am mixing node types in a View and I want nodes with a FileField to display the icon but I don't want to display the icon if the node doesn't have a FileField.
I imagine I can do this with a field theme template, but at first I kind of expected "Hide if empty" to exclude the icon if there was no file relationship.
Comment #34
dwightaspinwall CreditAttribution: dwightaspinwall commented@cduwe and @szt - not necessary to re-roll the view starting as "Files" type. You can add a "File: Usage" relationship on the file field in question, then the File: MIME Type will be available to display as a field. Do that, and check "Display and icon..." in the field config.