The "File Usage: File" relationship does not seem to respect the sort order of the image field.
If I use Content: Images to display images from an image field with multiple values, then the sort order (delta) is respected, but I cannot rewrite the image tag using this method.
I need to rewrite the image tag in order to get the Title and Description attributes included so they can be used as captions.
In order to rewrite the image tag in this way, I need to use File Usage: File relationship, and then use
(File) File: Alt (Alt)
(File) File: Title (Title)
(File) File: Name
and rewrite the name as an img tag using replacement tokens, i.e.
<img src="/sites/example.com/files/[nid]/[filename]" title="[field_title]" alt="[field_alt]" />
This works as far as displaying the images, but the delta sort order of the images appears to be ignored as soon as the "File Usage: File" relationship is added to the view.
Comments
Comment #1
jamesfk commented+1 - in fact the file relationship will output all files with no respect to the field either.
Comment #2
dawehnerWell the file usage: file is a relation from node to file_usage not from the images of a node to file_usage.
That's basically impossible to fix as the sql data simply can't do what you want, i'm sorry for that.
Comment #4
lorique commentedI know this is closed, but for those who come across this looking for a solution, i can say that there is one if you don't mind getting your hands dirty with some code.
My case:
In my case we have a gallery page where we need to take out all media on a node, and list them in the correct order. The node contains 2 media fields, primary and secondary, where primary is used for displaying the node in list views, and secondary is shown in some list views, and always in full view. When displaying the gallery.
My solution
I created a content view, added a contextual filter on NID on it for placing on the node page. Then i added a relationship to file usage, and then i set the view to render fields, only rendering the File: Rendered with the file usage relationship on it. This gives us a view which takes out all the files on a node, and renders them (We use file entity and file view modes for rendering) the way we want it.
Next comes the code bit.
I added the following code to the feature where i exported my view:
The code adds a left join on both my field data tables, and then orders them by the delta's. The ifnull command checks if the first variable (pm.delta) is null, and if it is uses the other argument (sm.delta) for ordering. Otherwise its pretty streight forward.
I'm planning a module with a new views relationship, and ordering option for views, so it can be configured rather than coded. Until then, this will hopefully help anyone running into this issue on their way to a solution.
Comment #4.0
lorique commentedwrapped img tag in code tags.