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;
}
}