This field is designed to let users attached an oembed object (eg a YouTube video) to a page or dataobject. It stores the oembed result information in an EmbedObject for easy access from the template (or wherever you want it).
Work in progress.
Nathan Cox ([email protected])
- SilverStripe 3.1+
- Place the files in a directory called mapfield in the root of your SilverStripe installation
- Visit yoursite.com/dev/build to rebuild the database
Make a has_one relationship to an EmbedObject then create an EmbedField in getCMSFields:
class Page extends SiteTree {
// has one video
static $has_one = array(
'Video' => 'EmbedObject'
);
function getCMSFields() {
$fields = parent::getCMSFields();
// add the EmbedField for managing Video
$fields->addFieldToTab('Root.Main', $embedField = EmbedField::create('VideoID', 'Sidebar video'));
// Specify that only videos can be embedded here (optional)
// Options are video, rich, link, photo or false (for any)
$embedField->setEmbedType('video');
return $fields;
}
}
Gives us:
In the page template the video can now be embedded with $Video
.
Each embed type is rendered with it's own template (eg EmbedObject_video.ss and EmbedObject_photo.ss). The default templates just return the markup generated by SilverStripe's OembedResult::forTemplate(). You can override them in your theme:
themes/mytheme/templates/Includes/EmbedObject_video.ss:
<div class='flex-video self-sizing' style='padding-bottom:$AspectRatioHeight;'>
$HTML
</div>
This can be combined with your own CSS to make aspect ratio aware flexible video (see http://alistapart.com/article/creating-intrinsic-ratios-for-video).