Adds embed and video a DataObjects along with a DataExtension to apply embed capabilities to existing objects.
Composer is the recommended way of installing SilverStripe modules.
composer require gorriecoe/silverstripe-embed
- silverstripe/framework ^4 | ^5
As a relationship to Embed Dataobjects
use gorriecoe\Embed\Models\Embed;
class ClassName extends DataObject
{
private static $has_one = [
'Embed' => Embed::class,
'Video' => Video::class
];
public function getCMSFields()
{
// ...
$fields->addFieldsToTab(
'Main',
[
HasOneButtonField::create('Embed', 'Embed', $this),
HasOneButtonField::create('Video', 'Video', $this),
]
);
// ...
}
}
Or update current DataObject to be Embeddable with DataExtension
use gorriecoe\Embed\Extensions\Embeddable;
class ClassName extends DataObject
{
private static $extensions = [
Embeddable::class,
];
/**
* List the allowed included embed types. If null all are allowed.
* @var array
*/
private static $allowed_embed_types = [
'video',
'photo'
];
/**
* Defines tab to insert the embed fields into.
* @var string
*/
private static $embed_tab = 'Main';
}
Several options can be set via Config
to control the behaviour of silverstripe-embed
These are set via the DataObject the Embeddable
data extension is applied to (which includes both Embed
and Video
)
E.g. as in the data extension example above with the embed_tab
option.
embed_tab
string Default:"Main"
- Name of the CMS edit form tab to display under.allowed_embed_types
array of strings Default:null
- allowed "types" ornull
for any.validate_embed
bool Default:false
- Whether to fetch and evaluate the validity of the embed URL (e.g. on save). Relies onallowed_embed_types
.cache_image_as_asset
bool Default:false
- Whether to download and save copies of thumbnails or photo type embeds as assets.embed_folder
string Default:null
- Name of the folder to store downloaded assets into. Will fall back to class name if not set. Relies oncache_image_as_asset
.