Skip to content

Adds embed and video a dataobject along with dataextension to apply embed to existing objects.

License

Notifications You must be signed in to change notification settings

NightJar/silverstripe-embed

 
 

Repository files navigation

Silverstripe embed

Adds embed and video a DataObjects along with a DataExtension to apply embed capabilities to existing objects.

Installation

Composer is the recommended way of installing SilverStripe modules.

composer require gorriecoe/silverstripe-embed

Requirements

  • silverstripe/framework ^4 | ^5

Maintainers

Usage

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

Options

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" or null for any.
  • validate_embed bool Default: false - Whether to fetch and evaluate the validity of the embed URL (e.g. on save). Relies on allowed_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 on cache_image_as_asset.

About

Adds embed and video a dataobject along with dataextension to apply embed to existing objects.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%