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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

David Stosik’s picture

stephen Piscura’s picture

David,

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.

David Stosik’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev

Hi, patch applies as is on 2.x-dev, and works as well !

David

David Stosik’s picture

Dave Reid’s picture

Version: 7.x-2.x-dev » 7.x-1.x-dev

The Media field type is already deprecated, so this would not be committed to 7.x-2.x.

stephen Piscura’s picture

Dave (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?

Dave Reid’s picture

Views already provides a file usage and file field relationships that just work, so there is nothing that has to be done there.

stephen Piscura’s picture

Thanks 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.

aaron’s picture

don'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.

stephen Piscura’s picture

Aaron,

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?

David Stosik’s picture

Dave, 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.

Shawn DeArmond’s picture

I have tried patch #1 on 7.x-1.x and can confirm that it works as described.

geek-merlin’s picture

supp!

Shawn DeArmond’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +D7 stable release blocker

Let's commit this.

Shawn DeArmond’s picture

Status: Reviewed & tested by the community » Needs review

Now 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.

anavarre’s picture

Subscribe

skottler’s picture

Subscribe.

Anonymous’s picture

Assigned: David Stosik »
Anonymous’s picture

Here'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.

Shawn DeArmond’s picture

Reviewed. Works on 2.x.

Contrary to what I said in #15, this patch IS necessary.

Shawn DeArmond’s picture

Status: Needs review » Reviewed & tested by the community

RTBC

aaron’s picture

Status: Reviewed & tested by the community » Fixed

committed to 7.x-1.x and 7.x-2.x . thanks!

ZuluWarrior’s picture

Sub

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

pinkonomy’s picture

Is 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