As it was suggested by pcambra.
I've given it a go, and here is an attached patch, which gets it working.
Problem is, we have to do this which I think its not very nice, inside our hook_field_formatter_view implementation:
// media module provides the items as objects while core as arrays.
if($field['type'] == 'media'){
foreach($items as $delta => $item) {
$items_fixed[] = get_object_vars($item);
}
$items = $items_fixed;
}
So until I get this clarify if it's going to stay this way in media module, I'm reluctant to committing this patch. Feel free to test it though.
Comments
Comment #1
pcambraThank you Manuel!
I'll test it as soon as I can
Comment #2
manuel garcia commentedJust so you know people, I filled a bug report with media module, as aaronwinborn told me that this is probably legacy stuf from pre-entity ages in D7:
#982180: $items in formatters are objects while core provides arrays
So this patch will not go in as is. We will wait until that bug is fixed in media module, then add support for it.
It should be as simple as applying the small patch attached, once that's done.
Comment #3
manuel garcia commentedKnow that if you help out in fixing that bug, you will:
1. Learn lots of cool things about media module.
2. Help get this feature in quicker.
Comment #4
Chris Gillis commentedAll we really need to do is add one line just inside the foreach (line 134)
$items[$delta] = $item = (array)$item;If we do this, we can add media support, which will greatly enhance the popularity of this module, and also assist in early adoption of Drupal 7. (This is currently the best/only gallery of its kind for D7)
As this line is only typecasting, it is a forward-compatible hack, and should not have any negative consequences once media module fixes their bug.
(mind if I switch this back to needs review?)
On another note, there are PHP notices everywhere for "undefined index". This module needs a whole lot of "if not empty"s... but that's irrelevant to this issue.
Comment #5
Chris Gillis commentedSorry, patch attached
Comment #6
Chris Gillis commentedOops, try this one:
Comment #7
manuel garcia commentedThanks Chris for the proposed solution, I'm very tempted to include this, as it seems a more maintainable approach than my original patch.
I've been testing this today a bit, and made a few changes to the patch, nothing major (find it attached).
I'm not sure wether to open this door just yet, because I've fond that so far galleryformatter only works properly with uploaded images through media module, and not from media_flickr for example. As for the flickr media module, I honeslty couldnt get it to work, see #1035866: What is and isn't possible with the 7.x dev version? so perhaps it isnt our fault.
Comment #8
tommyk commentedThe patch in #7 doesn't really work anymore. Is there any chance that this issue can be revisited? I don't know enough PHP to understand how to propose changes, unfortunately.
I'm using Media module in Drupal 7 and would really like to be able to use media images in a slideshow.
Comment #9
manuel garcia commentedIntegration with media module has to wait a bit until it gets a bit more stable TommyK, it's not nice to have to make sure our items are arrays if coming from media module... since when that's fixed in media module we'd have a bug in galleryformatter.
Also see #1018640: [meta] How to help get Media to 1.0 release and beyond
Comment #10
manuel garcia commentedOK I did a bit more checking, and we should work on this now that #1064502: Fatal error: Cannot use object of type stdClass as array in modules/field/field.form.inc on line 193 has been fixed.
Only problem is that that patch was committed on May 17, and the latest beta4 release is from April 27.
So we could work on it on the galleryformatter dev branch, and sync our next release with media module's next one, to avoid problems on users trying to use it with media.
Bumping the priority, I think it's important to have this in the next stable release.
Comment #11
tommyk commentedThanks for looking into this! I'll be happy to test patches or dev versions and report back.
Comment #12
Allium sativum commentedAny news about this issue? I'm desperatly searching an easy to handle image gallery for drupal7 and galleryformatter seems to be the most promising project to me. But I realy need the integration with the media module :-(
Comment #13
manuel garcia commentedI've done some checking on the current state of dev Media, and we still have a similar problem.
$item is now an array, but it includes an object $file with all the file information, so it stil needs further processing. Not sure whether this is something Media will fix or if it will stay like that.
We still have time so I guess we wait a bit on Media to settle down.
Comment #14
manuel garcia commentedOK, I've gone ahead and added support, we can't wait all year for things to standardize with core from media module.
We'll handle problems with it if / when they come.
I've committed a worked out version of what was being talked above, which required a bit more processsing to get the uri and filename, and to prevent other types of media than images from being in the gallery. At least for now this is how it will be.
Please do test with the current stable release of media, see if it works stil. I have only done testing with the latest dev version of media.
If all goes well, I'll probably make a new release of the module soon.
Comment #15
urlaub commentedThank you for the Media module support, sounds great!
But does that mean that I can have videos or thumbs of videos in Gallery formatter?
I tried to have videos and photos together in my gallery, but it doesn't work?
Could you update your demo gallery including a youtube video in case it is working?
Screenshot with Iamge Error:
http://www.diigo.com/item/image/1hwbg/jqox
Comment #16
manuel garcia commentedThanks urlaub for testing this.
Like I mention in my previous comment, currently there's only support for images from media field, nothing else. I've tried using youtube videos but what I get from media module does not include any thumbs, so for now this is how it is.
Comment #18
nicolash commentedI'm trying to get this to work with media and colorbox, but can't really find where I can set the formatter to open up a larger version on a thumbnail.
In "manage display" for the content type fields I still get the regular media styles:
https://skitch.com/nikkenheimer/fpg62/system
And in the media file styles options I get galleryformatter_slide and _thumb, which seem to be for the actual display within the gallery:
https://skitch.com/nikkenheimer/fpg9e/system
Could somebody help me out in what I'm missing?
Comment #19
nicolash commentedFWIW, for my simple requirement I can use what's discussed here for now: #1079300: showstoppers for using media module, in case it helps someone. Still would be great to get some info on how galleryformatter can work with media/colorbox.