Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mfer’s picture

Component: Code » Documentation
Category: feature » support

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

JacobSingh’s picture

This would be AWESOME!

Jackinloadup’s picture

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

effulgentsia’s picture

Component: Documentation » Code
Category: support » feature

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

aaron’s picture

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

iko’s picture

Hi,

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

nirbhasa’s picture

Here 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

ogi’s picture

subscribe

iko’s picture

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

lelizondo’s picture

subscribing.

Niklas Fiekas’s picture

Subscribe.

webankit’s picture

+1, will be a very good feature

JacobSingh’s picture

Can anyone who has started on this please comment on what's working and what's not?

lelizondo’s picture

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

JacobSingh’s picture

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

arthurf’s picture

Jacob-

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.

thomas4019’s picture

subscribing

presleyd’s picture

A view for selecting the media in the media browser would be perfect. I really love Media but the browser needs a little love.

jeffwidman’s picture

subscribe

AndrzejG’s picture

subscribe

neurojavi’s picture

Subscribing

neurojavi’s picture

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

anavarre’s picture

Subscribing

dlumberg’s picture

FileSize
6.95 KB

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

marcvangend’s picture

Subscribing.

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.

SanderJP’s picture

subscribe..

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.

lelizondo’s picture

Status: Active » Needs work

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

marcvangend’s picture

Marked #1165722: Exposed sorting widget as duplicate. Correct me if I'm wrong, but that request should be covered by the work done here, right?

Hi, it would be great to be able to sort the media files on file type. If I could access the multimedia assets' fields in Views it would be no problem, but since I can't, can anyone figure out if this is hard to make?

aaron’s picture

#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)."

aaron’s picture

and here's a patch of #24.

aaron’s picture

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

aaron’s picture

the other @todo (noted by arthur) is we need to add pagination as well.

aaron’s picture

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

marcvangend’s picture

I 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:

/**
 * Implements hook_views_api().
 */
function media_views_api() {
  return array(
    'api' => '3.0-alpha1',
  );
}

If that's an implementation of hook_views_api, the function name should be media_views_views_api, right?

good_man’s picture

Status: Needs work » Needs review
FileSize
25.55 KB

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

RonP’s picture

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

safetypin’s picture

I'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?

dlumberg’s picture

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


- Ensure the default view at includes/media.views_default.inc is actually included.

@marcvangend #34 good catch it will probably fix this.


- Fix namespace collision for media.library.js (where does this problem expose itself? i don't actually see it.)

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


- 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)."

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.


dlumberg’s picture

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

HnLn’s picture

sub

rickvug’s picture

sub.

good_man’s picture

@dlumberg: can you provide info. re. your patch? what you've done? so we our patches won't intersects and do repeated stuff.

CrashNet’s picture

Subscribing...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?

dlumberg’s picture

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

dlumberg’s picture

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

Status: Needs review » Needs work

The last submitted patch, add-views-3-support-to-media-962110-45.patch, failed testing.

good_man’s picture

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

g76’s picture

subscribe

achton’s picture

Subscribing.

dlumberg’s picture

@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:

  • The default view does not work.
  • Selecting another tab and then reselecting the views tab in the Media Browser will reload and append the list of available media

Can we get this committed into a branch in git so that we have a base to work from?

dlumberg’s picture

And this patch will make all of the changes to media that are required to get it to work.

Things I've done:

  • Wrote a Views Display that outputs into the same JSON that the Media Browser Library uses
  • Wrote a Views Style to work with the Views Display
  • Modified the media_browser_plugins_api to add some necessary functionality
  • Modified the Media Browser Library Javascript to be modular and reusable for Views integration
  • Modified the media fields settings form to include views integration in the Media Browser
  • Added media_views submodule of media to integrate Views into media
good_man’s picture

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

good_man’s picture

@dlumberg, just to make sure, your patch in #44 and so on are based on aaron's patch in #30?

dlumberg’s picture

@good_man

This patch is based off of 7.x-1.x in git.

dlumberg’s picture

Status: Needs work » Needs review
das-peter’s picture

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

Status: Needs review » Needs work

The last submitted patch, add-display-field-for-file-views-962110-56.patch, failed testing.

dlumberg’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, add-display-field-for-file-views-962110-56.patch, failed testing.

aspilicious’s picture

Watch out for the "\ No newline at end of file" lines

das-peter’s picture

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

dlumberg’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, add-display-field-for-file-views-962110-61.patch, failed testing.

keha3912’s picture

sub

webflo’s picture

cpelham’s picture

subscribe

TripX’s picture

sub

Dave Reid’s picture

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

dlumberg’s picture

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

kingjohnnet’s picture

sub

ZuluWarrior’s picture

sub

puidu’s picture

sub

Dave Reid’s picture

Title: Views 3 Support » Add views handlers for the media field type

Retitling based on original issue request. Related: #1201936: Move the media field to a non-required submodule

Dave Reid’s picture

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

axe312’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, add-display-field-for-file-views-962110-61.patch, failed testing.

djanousek’s picture

subscribing

aaron’s picture

Status: Needs work » Closed (duplicate)