-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from DoggersHusky/SilverStripe4
SilverStripe 4
- Loading branch information
Showing
11 changed files
with
141 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ Nathan Cox (<[email protected]>) | |
|
||
Requirements | ||
------------ | ||
* SilverStripe 3.1+ | ||
* SilverStripe 4.0+ | ||
|
||
Documentation | ||
------------- | ||
|
@@ -30,40 +30,42 @@ Usage Overview | |
Make a has_one relationship to an EmbedObject then create an EmbedField in getCMSFields: | ||
|
||
```php | ||
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; | ||
} | ||
|
||
namespace { | ||
|
||
use SilverStripe\CMS\Model\SiteTree; | ||
use nathancox\EmbedField\Model\EmbedObject; | ||
use nathancox\EmbedField\Forms\EmbedField; | ||
|
||
class Page extends SiteTree | ||
{ | ||
private static $db = []; | ||
|
||
private static $has_one = [ | ||
'MyVideo' => EmbedObject::class | ||
]; | ||
|
||
public function getCMSFields() { | ||
$fields = parent::getCMSFields(); | ||
|
||
$fields->addFieldToTab('Root.Main', EmbedField::create('MyVideoID', 'Sidebar video')); | ||
|
||
return $fields; | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Gives us: | ||
|
||
![example embedfield](http://static.flyingmonkey.co.nz/github/silverstripe-embedfield/embedfield-1.png) | ||
![example embedfield](https://i.ibb.co/Hxz7VGB/embedfield.jpg) | ||
|
||
|
||
In the page template the video can now be embedded with `$Video`. | ||
In the page template the video can now be embedded with `$MyVideo`. | ||
|
||
|
||
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: | ||
themes/mytheme/templates/nathancox/EmbedField/Model/EmbedObject_video.ss: | ||
```html | ||
|
||
<div class='flex-video self-sizing' style='padding-bottom:$AspectRatioHeight;'> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.