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.
Well, I needed to retrieve, in a views, for each result node, all media files attached to the node on a selected field (from Fields API). This allowed me to have many different media fields attached to a node type, keeping the possibility to distinguish one from the other in my views.
So here it goes, the little patch is below, and gives new Relationships in views, one per media field. When you add one in your views, you are then able to retrieve any field linked to the file entity attached to the node in the media field.
Regards,
David
Comment | File | Size | Author |
---|---|---|---|
#19 | media_views_relationship-1236232-19.patch | 1.38 KB | Anonymous (not verified) |
#10 | Garbled fields as seen from Views UI | 281.7 KB | stephen Piscura |
#8 | Views UI view of the file-field view | 295.64 KB | stephen Piscura |
#8 | The file-field view attached to a node via EVA | 371.67 KB | stephen Piscura |
#1 | media_field_views_relationship-1236232-1.patch | 1.17 KB | David Stosik |
Comments
Comment #1
David Stosik CreditAttribution: David Stosik commentedComment #2
stephen Piscura CreditAttribution: stephen Piscura commentedDavid,
Is this working for you in 7.x-1.x-dev? Would it be possible for you to roll out a version of this patch for the 7.x-2.x-dev branch? What you've described is exactly what i need... Thanks for your work on this.
Comment #3
David Stosik CreditAttribution: David Stosik commentedHi, patch applies as is on 2.x-dev, and works as well !
David
Comment #4
David Stosik CreditAttribution: David Stosik commented#1: media_field_views_relationship-1236232-1.patch queued for re-testing.
Comment #5
Dave ReidThe Media field type is already deprecated, so this would not be committed to 7.x-2.x.
Comment #6
stephen Piscura CreditAttribution: stephen Piscura commentedDave (Reid),
I didn't realize this patch specified a media asset, as opposed to a file entity. Thanks for clarifying that.
I realize it's all too convenient for me to ask this—in that i don't have the skills to do so myself—but is there anything in this patch that can be reworked for 7.x-2.x or for File Entity in order that the same goal described by David may be achieved?
Comment #7
Dave ReidViews already provides a file usage and file field relationships that just work, so there is nothing that has to be done there.
Comment #8
stephen Piscura CreditAttribution: stephen Piscura commentedThanks Dave. This may be getting into the realm of an issue better suited for Views itself, but in that i've spent a lot of time working with the "File Usage: File" relationship to no avail, i thought i'd share my experience. I'd be happy to post directly to the Views issue queue if needed...
Created a view containing a file-field called "Media." "Media" allows for unlimited items. They're all displaying. Excellent.
The fields attached to these files are also needed for the view. They're not available by default, so a relationship is needed. "File Usage: File" seems like the right one.
Great, now all fields attached to the files are available. Upon adding two custom fields, "field_title" and "field_description", things get weird.
There seems no way to associate the specific field data with its corresponding file. All the data seems to order at random, multiple times over.
How does one specify "This title belongs to file A and none other", "This description belongs to that file B and none other", "This set of tags belongs to file C and none other", etc.? After a lot of time spent trying to solve this, i've found no solution.
I've attached some screenshots, which might help illustrate what i'm talking about.
By the way i'm working the 7.x-2.x branch.
Comment #9
aaron CreditAttribution: aaron commenteddon't select from the 'file usage: file' group for that. instead, you will find new fields under the 'File' group, when you look for fields, filters, etc.
Comment #10
stephen Piscura CreditAttribution: stephen Piscura commentedAaron,
Thanks for your reply. Having added the "File: File Usage" relationship, i am selecting from the "File" group—not the "File: File Usage" group—when i go to add fields/filters/etc. to the view. I do see all of the fields associated with my files, it's just that when i add any of these fields, they're not listed with their respective files. The view just seems to add these fields at random with multiple instances of the same data. That is, Title A is listed with File C, Description B is listed with File A, Title A is listed with file D and so on.
Is there another relationship i should be selecting, instead of "File: File Usage"? Could the fact that my file-field allows for unlimited values be causing the problem?
Comment #11
David Stosik CreditAttribution: David Stosik commentedDave, thanks for the complete feedback. Actually, I only worked on this topic with Media 1.x, and didn't find anything fullfilling what I was trying to achieve (and the only time I tested 2.x, quickly, I didn't find anything either...). Thus I tried to work out some relationship allowing me to retrieve a file associated to a selected file_field / media_field.
This is already done by file_entity-1.x, and usable with media-2.x, so that's a great thing !
Stephen, I can't reproduce your problem. Could you please provide more details about your views (or even better a file containing an export) ?
By the way, if you want to target at a selected file field, you'd better use "Content: Field name:fid" relationship instead of "File Usage: File". ;)
Also, please ensure that the appropriate relationship is selected for each displayed field.
Comment #12
Shawn DeArmond CreditAttribution: Shawn DeArmond commentedI have tried patch #1 on 7.x-1.x and can confirm that it works as described.
Comment #13
geek-merlinsupp!
Comment #14
Shawn DeArmond CreditAttribution: Shawn DeArmond commentedLet's commit this.
Comment #15
Shawn DeArmond CreditAttribution: Shawn DeArmond commentedNow wondering if this issue is a duplicate of #1213218: Not able to use file or image fields as a relationship
I haven't tested this with the newest dev of Views.
Comment #16
anavarreSubscribe
Comment #17
skottler CreditAttribution: skottler commentedSubscribe.
Comment #18
Anonymous (not verified) CreditAttribution: Anonymous commentedComment #19
Anonymous (not verified) CreditAttribution: Anonymous commentedHere's the patch. It's basically the same as David Stosik's patch in #1 but media.views.inc is in the includes directory and I added PHP doc to the new file.
Comment #20
Shawn DeArmond CreditAttribution: Shawn DeArmond commentedReviewed. Works on 2.x.
Contrary to what I said in #15, this patch IS necessary.
Comment #21
Shawn DeArmond CreditAttribution: Shawn DeArmond commentedRTBC
Comment #22
aaron CreditAttribution: aaron commentedcommitted to 7.x-1.x and 7.x-2.x . thanks!
Comment #23
ZuluWarrior CreditAttribution: ZuluWarrior commentedSub
Comment #25
pinkonomy CreditAttribution: pinkonomy commentedIs this patch included in the 7.x-1.2 version of Media module?I cannot create a view with images/videos using the Media module.Any suggestions on this?What type of view should i create?thanks a lot