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.
How about exposing the data in Media module to Views 3.
How about exposing the data in Media module to Views 3.
Comments
Comment #1
mfer CreditAttribution: mfer commentedI see that Media module wraps / uses the file_managed table as the base of the entity. This means to create a view you choose File as the type.
How to build Media views would be useful to document.
Comment #2
JacobSingh CreditAttribution: JacobSingh commentedThis would be AWESOME!
Comment #3
Jackinloadup CreditAttribution: Jackinloadup commented@mfer just out of personal curiosity, what kind of use-cases are you thinking about? Always love finding new ways to deal with what data I have available.
Comment #4
effulgentsia CreditAttribution: effulgentsia commentedI'm not sure this really works out of the box in any useful way, so setting back to feature request. I'm happy to be proven wrong on this, though. If someone can document how to make a useful view with the module as-is, that would indeed be awesome.
Comment #5
aaron CreditAttribution: aaron commentedthis has long been on the road map for development. so we can do things like nrembrowser does (allowing an custom administrative view tab on the browser). probably not before the release. but soon, i hope...
Comment #6
iko CreditAttribution: iko commentedHi,
I may provide a specific use case where some work on Media module would be necessary for a better Views integration.
My aim : a view of medias - OK, the "files" type view is OK. But the medias are associated to nodes, and I need to get some informations from the nodes. Which means "relationships", in Views' language.
Among the avalaible relationships, the File usage : node (A node that is associated with this file, usually because this file is in a field on the node.) works with media uploaded through a field (either a file field type or a multimedia asset field type), but files uploaded as media, via the WYSIWYG editor, are not "seen" by Views.
I absolutely don't know how it could be made possible to create the technical relationship between the media and the node, but such a relationship would also be useful for http://drupal.org/node/933590 : Provide a way for users to see where files are in use.
Hope this will be an interesting clue and thanks a lot for your work !
Marie-Hélène
Comment #7
nirbhasa CreditAttribution: nirbhasa commentedHere is another use case: if you attach fields to a media asset, and you would like a listing of uploaded media files, plus their attached field data.
For example: you upload a file as a video multimedia asset, and you have added image and 'HD version' file fields to the file. It would be nice to be able to output a listing containing the URL of all file and image fields. In this way, with some theming, you could then generate playlists using Views for use in media players
Comment #8
ogi CreditAttribution: ogi commentedsubscribe
Comment #9
iko CreditAttribution: iko commentedAnother idea : the relationships between the node entity and the media entity might be managed with the Relation module.
[edit] After further investigations, it should be possible to make the file_usage table aware of wysiwyg-inserted medias for a Views exposition due to the reference to fid in the media filter :
[[{"type":"media","view_mode":"media_large","fid":"2","attributes":{"alt":"","class":"media-image","title":"","typeof":"foaf:Image","wysiwyg":"1"}}]]
. When it's a usual link to the file (a href etc), the usage appears in file_usage.Comment #10
lelizondo CreditAttribution: lelizondo commentedsubscribing.
Comment #11
Niklas Fiekas CreditAttribution: Niklas Fiekas commentedSubscribe.
Comment #12
webankit CreditAttribution: webankit commented+1, will be a very good feature
Comment #13
JacobSingh CreditAttribution: JacobSingh commentedCan anyone who has started on this please comment on what's working and what's not?
Comment #14
lelizondo CreditAttribution: lelizondo commentedThere is a branch where the developers are working, and there are some commits http://drupalcode.org/project/media.git/shortlog/refs/heads/7.x-1.x-views but I don't know if is working or not.
Comment #15
JacobSingh CreditAttribution: JacobSingh commentedIt didn't work at all for me. The default views did not show up at all... I'll ask arthur about it. I think he might have built it against an earlier version of views.
Comment #16
arthurf CreditAttribution: arthurf commentedJacob-
A few things:
* I put a interface for selecting which views are available in the browser here: admin/config/media/browser/views
* The default view (includes/media.views_default.inc) is views 3
I was getting the embedded view inside of the media browser with pagination. I had not yet applied the necessary formatting to the views results so that they were selectable in the the browser.
Comment #17
thomas4019 CreditAttribution: thomas4019 commentedsubscribing
Comment #18
presleyd CreditAttribution: presleyd commentedA view for selecting the media in the media browser would be perfect. I really love Media but the browser needs a little love.
Comment #19
jeffwidman CreditAttribution: jeffwidman commentedsubscribe
Comment #20
AndrzejG CreditAttribution: AndrzejG commentedsubscribe
Comment #21
neurojavi CreditAttribution: neurojavi commentedSubscribing
Comment #22
neurojavi CreditAttribution: neurojavi commentedI've tested this branch and I get a php error aboutn media entity. I've previously updated media module to las dev version (which includes commit for issue #1086958: Switch from Media Entity to File Entity).
Need this branch an upgrade for using the new file entity and not the dissapeared media entity?
In any case, is this branch needed to get file entities in a view? Or it's only about using views in media browser?
Without this I'm able to create a view of file entities but I'm not able to show them as images or using the formatters provided by media (the view modes)...
Thanks.-
Comment #23
anavarreSubscribing
Comment #24
dlumberg CreditAttribution: dlumberg commentedI've got this almost there. I moved the code from the views branch into the attached module and borrowed heavily from the references module.
I'm new to git so I think I determined that either I don't have commit privileges or I just have no idea how to push the branch.
This works with file views and with node views. I created a Display that returns the same JSON the library module uses (reusing the media module functions).
The only 2 things (that I can remember) that need to get done before this actually works are to:
- Get the form/element that called the media browser to get the field settings to work right.
**DONE ** see #1163100: Add form field awareness to Media Browser plugins
- The module tries to reuse the media.library.js but there's a namespace collision.
To see it in action grab the "path" from a "Media Browser" display in views and change 'getMediaUrl' in media/includes/media.browser.inc
This is based off of the 7.1-x.1 branch so it requires the latest dev version with the file_entity module.
Comment #25
marcvangendSubscribing.
The least I would expect from Media-Views integration, is that I can create a simple image gallery by placing images in a grid view. Currently I can create a grid with file names, paths, sizes etc., but (unless I'm missing something) I can't display the media itself.
Comment #26
SanderJP CreditAttribution: SanderJP commentedsubscribe..
Maybe this is not the right issue, but will this also allow you to use the fields attached to a media file in Views? I have images as multimedia assets with tags/name/photographer fields attached to it. But I cannot use those fields in Views.. will that be possible with this? Thanks.
Comment #27
lelizondo CreditAttribution: lelizondo commented@dlumberg good work but I think it would be easier for all of us to review if this was a patch and not a zip.
Comment #28
marcvangendMarked #1165722: Exposed sorting widget as duplicate. Correct me if I'm wrong, but that request should be covered by the work done here, right?
Comment #29
aaron CreditAttribution: aaron commented#24 is great work so far, thanks @dlumberg! Unfortunately, when I build the view, I get an error: "Warning: Invalid argument supplied for foreach() in views_object->_set_option_defaults() (line 68 of /var/www/d7-media/sites/all/modules/views/includes/base.inc)."
Comment #30
aaron CreditAttribution: aaron commentedand here's a patch of #24.
Comment #31
aaron CreditAttribution: aaron commentedThat said, after following the instructions at #24, I am able to make the view work (just with the error posted). Would be nice to also allow the preview to work as a @todo.
Awesome work so far! Thanks, @arthur, @dlumberg, and everyone else working hard on this issue.
Comment #32
aaron CreditAttribution: aaron commentedthe other @todo (noted by arthur) is we need to add pagination as well.
Comment #33
aaron CreditAttribution: aaron commentedHere's a compact @todo list to help track progress of this issue:
- Fix the error: "Warning: Invalid argument supplied for foreach() in views_object->_set_option_defaults() (line 68 of /var/www/d7-media/sites/all/modules/views/includes/base.inc)."
- Build out the UI for admin/config/media/browser/views (which currently displays "Not sure what should go here, settings for Media browser views.")
- Ensure the default view at includes/media.views_default.inc is actually included.
- Fix namespace collision for media.library.js (where does this problem expose itself? i don't actually see it.)
- Tie the browser configuration (above) to 'getMediaUrl' in media/includes/media.browser.inc (if it's set to be the default 'library' view).
- Add pagination to the browser.
There are more things I'd like to see, but we can add additional issues for these, rather than holding up committing this work:
- Optionally tie in additional views to more tabs on browser.
- Respect any exposed filters from the views.
- Beef up any relationships/arguments/field/sort/filter handlers, etc. (Maybe? Not sure how thorough Views handling of files are atm).
- Document how to integrate Media + Views.
- Add documentation to the module's internal help page.
Comment #34
marcvangendI just installed and tried the module from #24. I see that there is a new display type, but I cannot seem to figure out what it does or what it's supposed to do. Am I missing something?
By the way I think I found a mistake in media_views.module:
If that's an implementation of hook_views_api, the function name should be media_views_views_api, right?
Comment #35
good_man CreditAttribution: good_man commented@marcvangend: that's right.
I've made many changes, I tried to list them here:
- Tabs, trailing spaces
- Views warnings (invalid arguments)
- Undefined entity_info in media_views_get_views_options()
- Undefined index: media_views in media_views_field_settings_submit()
The views is now working for me, here are the steps to do for View beginners:
- Enable Media Views module
- Create new View (current built-in View does not work now, but in case it is, it'll replace this step).
- Create new display, under Displays title at top of the View besides Page tab, there is an add button, click on it and choose Media Browser.
- Add filters, fields especially the field that contain the media (Media Asset field), choose how it should be displayed (Preview, Large etc...).
- Now the View should be ready.
Most important TODO:
- Get the built-in View working.
- Preview of the View of display type Media Browser.
- Get the option "Use Media Browser views plugin" in Media Asset field working on node view (it should displays a tab for the selected view on node view).
@aaron comment #33 has a very good TODO, I'll try to do as many of them as I can.
Comment #36
RonP CreditAttribution: RonP commentedI would like to provide a use case.
My site is based on Railroad photographers.
Instead of building a boring gallery site I am focusing on location enabled blog posts, that have media handling the photos they took.
Views 3 could then, from the file taxonomy provided, make fancy galleries with content added as a major side feature.
Comment #37
safetypinI'd really like to help test this functionality, but I think I'm doing something wrong to apply the patch. I'm getting an error from one of the media extension modules (media_vimeo) that says that it can't find the MediaReadOnlyStreamWrapper class. Do I need to avoid testing this module in built-up installations?
Comment #38
dlumberg CreditAttribution: dlumberg commentedI originally didn't make a patch because I wasn't sure if it should be a submodule of media or if it should end up as it's own module.
@marcvangend #34 good catch it will probably fix this.
The library prototype was hard coded to use '#status', '#scrollbox', and '#media-browser-library-list' divs by their ids. When the Views Browser tried to reuse the same JS file the div ids ran into eachother and the Views Browser didn't display right. I changed media/js/plugins/media.library.js to be more modular and updated media/includes/media.browser.inc
I'll take a look into this, I was getting similar errors but I thought I had tracked them all down. I'll start over with a fresh install of this patch and see if I can reproduce it unless #35 fixed it (it is rolled into this patch).
Directions to use views in Media Browser:
Enable "Media Views" module.
Enable a view that uses the "Media Browser" display.
Go to /admin/structure/types/manage/CONTENT TYPE/fields and edit the field you want to add the view to.
At the bottom of the edit tab you'll find settings for using the "Media Browser" views that you have created.
Click on the media library selector and you'll now have a panel with your view.
Comment #39
dlumberg CreditAttribution: dlumberg commented#38 adds a new bug where selecting another tab in the browser and then returning to the views browser will reload the media list and append it.
Comment #40
HnLn CreditAttribution: HnLn commentedsub
Comment #41
rickvug CreditAttribution: rickvug commentedsub.
Comment #42
good_man CreditAttribution: good_man commented@dlumberg: can you provide info. re. your patch? what you've done? so we our patches won't intersects and do repeated stuff.
Comment #43
CrashNet CreditAttribution: CrashNet commentedSubscribing...exposure of media content to Views, essentially, as others have mentioned, to have the ability to create and filter playlists of media nodes created on your site.
As a possible (maybe ugly) temporary solution, would it be possible to add an image field to the media content type where the user can upload an image for the thumbnail, and then in Views, pull all thumbnails from the media nodes and link them to their respective full node with the embedded video?
Comment #44
dlumberg CreditAttribution: dlumberg commented@good_man I changed the media_views_api call to media_views_views_api to get the default to at least install. I haven't tested yet to see if the get_options error in views is fixed.
I made changes to media.library.js to fix the namespace collision.
I rolled #35 into it.
The media browser should now work with views as expected without having to change the getMediaUrl.
Comment #45
dlumberg CreditAttribution: dlumberg commentedugh, I inadvertently undid some of the changes I made when I applied the patch from #35
This is the patch that #38 should have been plus the default view is now showing up.
Sooner or later I will get the hang of this "patch workflow" it's all new to me and somewhat counter-intuitive.
**EDIT** UGH, now it's saying the patch is corrupt.
Comment #47
good_man CreditAttribution: good_man commentedPlease make sure to *list* your changes, some of your changes you did, I did them before in my patch. The last thing we need is repeated patches.
Comment #48
g76 CreditAttribution: g76 commentedsubscribe
Comment #49
achtonSubscribing.
Comment #50
dlumberg CreditAttribution: dlumberg commented@good_man see #44
This patch is based off of 7.x-1.x in git. I don't have the time to figure out how to patch a patch of a patch so I'm just uploading everything I've done.
It adds the media_views submodule to media.
2 known bugs:
Can we get this committed into a branch in git so that we have a base to work from?
Comment #51
dlumberg CreditAttribution: dlumberg commentedAnd this patch will make all of the changes to media that are required to get it to work.
Things I've done:
Comment #52
good_man CreditAttribution: good_man commentedOk now it's better with the list of changes, I'll try to merge my work into yours.
When you are ready for a review just change the status.
Comment #53
good_man CreditAttribution: good_man commented@dlumberg, just to make sure, your patch in #44 and so on are based on aaron's patch in #30?
Comment #54
dlumberg CreditAttribution: dlumberg commented@good_man
Comment #55
dlumberg CreditAttribution: dlumberg commentedComment #56
das-peter CreditAttribution: das-peter commentedThe attached patch is a patch for the patch ;) It extends the new media_views module with the possibility to display a file in a normal file view.
To achieve that the "pseudo" field "Display" is added to the definiton of the table "file_managed".
The related views handler offers an option to select the view mode which should be used to display the file.
This was the easiest / best way I could think of - suggestions for a better solution are very welcome :)
The patch contains only the added code relative to the patch from #50.
Comment #58
dlumberg CreditAttribution: dlumberg commented#56: add-display-field-for-file-views-962110-56.patch queued for re-testing.
Comment #60
aspilicious CreditAttribution: aspilicious commentedWatch out for the "\ No newline at end of file" lines
Comment #61
das-peter CreditAttribution: das-peter commentedFixed form element naming issue in my patch.
The patch won't apply to the current master since it contains only the added / modified code relative to the patch from #50
The idea behind that is to just show the changes I did to reach my goal - and thus maybe get suggestions how to solve it smarter.
Let me know if you prefer a patch which includes all the changes.
Comment #62
dlumberg CreditAttribution: dlumberg commentedComment #64
keha3912 CreditAttribution: keha3912 commentedsub
Comment #65
webflo CreditAttribution: webflo commentedRelated issue #1192326: Views field integration for file type/bundle
Comment #66
cpelham CreditAttribution: cpelham commentedsubscribe
Comment #67
TripX CreditAttribution: TripX commentedsub
Comment #68
Dave ReidHrm, the current approach of this patch is to take Views output and force it back into Media's browser via JSON results correct? If so, I believe this is the wrong approach. We should be seeking to replace the default media browser with a view that does similar things, but we win because we get automatic AJAX paging, filtering, etc.
Comment #69
dlumberg CreditAttribution: dlumberg commentedI agree, I was just trying to get a proof of concept working. I stopped developing this because it seems like there are a few different branches working on overhauling the media browser. I'd like to see where it settles before devoting more time to it.
Comment #70
kingjohnnet CreditAttribution: kingjohnnet commentedsub
Comment #71
ZuluWarrior CreditAttribution: ZuluWarrior commentedsub
Comment #72
puidusub
Comment #73
Dave ReidRetitling based on original issue request. Related: #1201936: Move the media field to a non-required submodule
Comment #74
Dave ReidActually I'm going to mark this as a duplicate of #1236232: Expose a views relationship for media fields which has a more recent patch. The rest of views integration is happening either in file_entity or in other separate issues.
Comment #75
axe312 CreditAttribution: axe312 commented#61: add-display-field-for-file-views-962110-61.patch queued for re-testing.
Comment #77
djanousek CreditAttribution: djanousek commentedsubscribing
Comment #78
aaron CreditAttribution: aaron commented