Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

YouTubeGallery and 2.4.2

Go to End

41 Posts   6258 Views


21 October 2010 at 7:05am (Last edited: 21 October 2010 7:05am), Community Member, 46 Posts


Is this working?
I've downloaded the latest daily build.
A few careful var_dumps show me data coming coming in including the html describing the videos I've asked for, but then all I see is "no videos returned" (or whatever the message is).
(xml handling is perhaps out of date?)

Do I need to start putting together something of my own, or should this module work?
(or are there better ways of doing a silverstripe youtube gallery?)



22 October 2010 at 9:50am (Last edited: 22 October 2010 9:50am), Community Member, 46 Posts

Ok - if anyone is wanting youtube gallery in 2.4, the google api has changed (now late October 2010).

Replace the extractVideoInfo($video) with this code and it will work in 2.4.2

    * Gets information from one <entry> tag from the feed
   function extractVideoInfo($video) {
      $data = array();
      $mediaentry = $video->children('');
      $attrs = ($mediaentry[0]->children('media', true));

      $data['Author'] = Convert::raw2xml((string)$video->author->name);
      $data['Title'] = Convert::raw2xml((string)$video->title); // Title of the video
      $data['HTML'] = trim((string)$video->content);
      $data['Description'] = Convert::raw2xml((string)$mediaentry->group->description);
    $yt = $mediaentry->children('');
$attrs = $yt->duration->attributes();
$length = $attrs['seconds'];
      $data['RuntimeMin'] = floor( $length/60);
      $data['Runtime'] = sprintf ("%dm%2ds",$data['RuntimeMin'], $length - ($data['RuntimeMin']*60));

      $attrs = $mediaentry->group->player->attributes();
      $data['PlayerURL'] = Convert::raw2xml((string)$attrs['url']);       
$attrs = $mediaentry->group->thumbnail[0]->attributes();
$thumbnail = Convert::raw2xml((string)$attrs['url']);

$data['SmallThumbnail'] = new ArrayData(array(
         'URL' => $thumbnail,
         'Width' => 100,
         'Height' => 80
      return $data;


11 November 2010 at 1:40am (Last edited: 11 November 2010 8:22am), Community Member, 107 Posts

Code works, seems like the pop up function doesn't work.


15 December 2010 at 5:53am (Last edited: 15 December 2010 5:55am), Community Member, 28 Posts

Hi everyone, thanks for the update I now almost have my YouTube Gallery up and running again thanks to this thread. I am having problems with the popup too though. I have got the popup working, but it contains the whole youtube page rather than just the video. The gallery page source shows something like this for each video:

<a params="lightwindow_width=,lightwindow_height=,lightwindow_loading_animation=false,
lightwindow_type=external" href=";feature=youtube_gdata_player"

All the other video info is being extracted and displayed fine on the gallery page, but I guess the PlayerURL link may not be quite right, and it doesn't look like any dimensions are being picked up from the video information. I did think that a PlayerURL link of the form:

might work better, but beyond that I'm stumped. Can anyone help?

Many thanks


21 December 2010 at 9:25am Community Member, 34 Posts

Looks like in editing the YouTubeService.php file to include the updated api, there are no longer any values defined for $PlayerWidth and $PlayerHeight and the YouTubeGallery.SS files calls them and receives no answer. Thus, you do not have a defined valued in the firebug console or source.

Can I ask why this was updated? If I use the original api on SS 2.4.3 it works for me and I then just have to comment out some of the duplicate js calls

The YouTube module is calling the prototype.js file a second time and causing an issue. I circumvented this by

Adding these lines into the init() function of YouTubeGallery.php after line 116:


This allows the module to work both with the lightwindow and without. It also gives me a smaller lightwindow.

I then Changed the original YouTubeService.php video player dimensions and have a working module that plays just the video.

Attached Files

25 January 2011 at 12:12pm (Last edited: 25 January 2011 12:13pm), Community Member, 107 Posts


Works perfect. Just curious as why you didn't modify YouTubeGallery.php? Anyway, if you do, then the Youtube module with the files you have is compatible with 2.4.

Thank you very much for fixing the code.


26 January 2011 at 11:19am (Last edited: 28 January 2011 4:49am), Community Member, 34 Posts

I am using the files I attached without modding the YouTubeGallery.php on a 2.4.4 install and am having no problems.

By changing the YouTubeService.php file to include the above code, you are no longer connecting to the YouTube API via REST interface.

In doing this you are now subject to the YouTube block in showing videos in an iframe. Which in turn means your videos may not display in the light window in all browsers. They would like you to use this method instead:

The announcement about this block is posted here:

By maintaining the original code and using the YouTube API via REST interface , you are not subject to the no frames block from youtube.

The only issue I did run into was the Thumbnail size. So I changed the YouTubeService.php to look like this

$data['SmallThumbnail'] = new ArrayData(array(
         'URL' => Convert::raw2xml((string)$thumbnailObjs[0]['url']),
         //'Width' => (int)$thumbnailObjs[0]['width'],
         //'Height' => (int)$thumbnailObjs[0]['height'],
         'Width' => 100,
    'Height' => 80,

Hope this helps anyone else that comes across this topic.


30 January 2011 at 4:15am Community Member, 107 Posts

Yes, removed the changes, made the update to YouTubeService.php, works fine. So other than updating YouTubeService.php, everything works as you have it packaged.

Thanks again.

Go to Top