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.

Archive

Our old forums are still available as a read-only archive.

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

New Module for pages with embedded YouTube video


Reply

3 Posts   1756 Views

Avatar
orientel

28 November 2007 at 1:17pm (Last edited: 28 November 2007 1:49pm), Community Member, 2 Posts

I'm trying to learn SilverStripe and I created a simple module to include an embedded youtube video in a page from CMS.

It works quite correctly, the only "bug" is that if a parameter (Border) has zero value it is not considered. Did I use a wrong data type? I tried varchar, text, int and if border is not zero (e.g. "Border=1") it works, if Border is equal to 0 not (it becomes "Border="):

class YouTubeVideo extends Page {

static $db = array(
   "Video" => "Varchar",
   "Color1" => "Varchar",
   "Color2" => "Varchar",
   "Border" => "Varchar",
   "Wmode" => "Varchar",
   "Width" => "Varchar",
   "Height" => "Varchar"
);

function getCMSFields($cms) {
$fields = parent::getCMSFields($cms);
$fields->addFieldToTab("Root.Content.Main", new TextField("Video","YouTube Video ID"));
$fields->addFieldToTab("Root.Content.Main", new TextField("Color1","Color 1", "0xd6d6d6"));
$fields->addFieldToTab("Root.Content.Main", new TextField("Color2","Color 2", "0xf0f0f0"));
$fields->addFieldToTab("Root.Content.Main", new TextField("Border","Border", "0"));
$fields->addFieldToTab("Root.Content.Main", new TextField("Wmode","Wmode", "transparent"));
$fields->addFieldToTab("Root.Content.Main", new TextField("Width","Width", "425"));
$fields->addFieldToTab("Root.Content.Main", new TextField("Height","Height", "355"));
return $fields;
}

}

class YouTubeVideo_Controller extends Page_Controller {

function Content(){
         return $this->Content.$this->EmbeddedVideo();
}

function EmbeddedVideo(){
      global $YouTubeUrl;

   $video = '<object width="'.$this->Width.'" height="'.$this->Height.'"><param name="movie" value="'.$YouTubeUrl.$this->Video.'&rel=1&color1='.$this->Color1.'&color2='.$this->Color1.'&border='.$this->Border.'"></param><param name="wmode" value="'.$this->Wmode.'"></param><embed src="'.$YouTubeUrl.$this->Video.'&rel=1&color1='.$this->Color1.'&color2='.$this->Color2.'border='.$this->Border.'" type="application/x-shockwave-flash" wmode="'.$this->Wmode.'" width="'.$this->Width.'" height="'.$this->Height.'"></embed></object>';

      return $video;
}

}

[url=http://www.orientel.altervista.org/youtubevideo.rar]Download module (save target as...)[/url]

Avatar
Sean

28 November 2007 at 5:57pm (Last edited: 28 November 2007 6:04pm), Forum Moderator, 921 Posts

Hi there,

Nice work!

You could probably do something like this on the Page class:

function Border() {
if($this->Border) {
return $this->Border;
} else {
return '0';
}
}

Calls to $this->Border can then be replaced with $this->Border()

0 isn't output, because if it's 0 it's null. So, I guess you have to explicitly pass the 0 on as a string instead.

The data type for Border should probably be 'Boolean', since it's only 1 or 0 correct? If that's also the case, you could use the field NumericField instead of TextField in getCMSFields() (so you can't input anything apart from a number). One of the arguments to NumericField also allows you to limit the characters for that field with maxlength, so if it's a boolean you can't input anything more than 1 character.

Cheers,
Sean

Avatar
orientel

29 November 2007 at 10:47am Community Member, 2 Posts

Thanks... it's strange for me that zero character is considered a null value in a Varchar or Text data field, however I understood the point (solution was simpler than expected).

I fixed and updated my module and it's working fine now (same url of first post, now also autoplay parameter is managed).

Thanks again for answer, bye!