DoggersHusky / silverstripe-embedfield

A SilverStripe form field for adding oembed objects (primarily videos) to pages or dataobjects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SilverStripe EmbedField

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.

Maintainer Contacts

Nathan Cox (me@nathan.net.nz)

Requirements

  • SilverStripe 3.1+

Documentation

GitHub

Installation Instructions

  1. Place the files in a directory called mapfield in the root of your SilverStripe installation
  2. Visit yoursite.com/dev/build to rebuild the database

Usage Overview

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:

example embedfield

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).

Known Issues

Issue Tracker

About

A SilverStripe form field for adding oembed objects (primarily videos) to pages or dataobjects


Languages

Language:PHP 61.8%Language:JavaScript 26.4%Language:CSS 6.2%Language:Scheme 5.6%