IMPR: Add video files

This commit is contained in:
Tony Air 2022-07-08 19:19:50 +02:00
parent 2f7d358dbe
commit c3c268488e
2 changed files with 23 additions and 17 deletions

View File

@ -9,15 +9,12 @@
namespace A2nt\ElementalBasics\Extensions; namespace A2nt\ElementalBasics\Extensions;
use A2nt\ElementalBasics\Elements\SliderElement; use A2nt\ElementalBasics\Elements\SliderElement;
use DNADesign\Elemental\Models\BaseElement; use SilverStripe\Assets\File;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Forms\CheckboxField; use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\DatetimeField; use SilverStripe\Forms\DatetimeField;
use SilverStripe\Forms\ToggleCompositeField; use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Forms\TreeDropdownField;
use SilverStripe\ORM\DataExtension; use SilverStripe\ORM\DataExtension;
use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\LiteralField;
use SilverStripe\ORM\ValidationResult; use SilverStripe\ORM\ValidationResult;
/** /**
@ -30,19 +27,23 @@ use SilverStripe\ORM\ValidationResult;
*/ */
class SlideImageEx extends DataExtension class SlideImageEx extends DataExtension
{ {
private static $db = [ private static $db = [
'Hide' => 'Boolean(0)', 'Hide' => 'Boolean(0)',
'DateOn' => 'Datetime', 'DateOn' => 'Datetime',
'DateOff' => 'Datetime', 'DateOff' => 'Datetime',
]; ];
private $_cache = [ private static $has_one = [
'element' => [], 'VideoFile' => File::class,
]; ];
public function getElement() private $_cache = [
'element' => [],
];
public function getElement()
{ {
if(!isset($this->_cache['element'][$this->owner->ID])) { if (!isset($this->_cache['element'][$this->owner->ID])) {
$this->_cache['element'][$this->owner->ID] = $this->owner->SlideshowElement(); $this->_cache['element'][$this->owner->ID] = $this->owner->SlideshowElement();
} }
@ -55,11 +56,11 @@ class SlideImageEx extends DataExtension
$el = $this->getElement(); $el = $this->getElement();
$img = $this->owner->Image(); $img = $this->owner->Image();
if(!$img) { if (!$img) {
return null; return null;
} }
if($el->getField('ImageOriginalSize')){ if ($el->getField('ImageOriginalSize')) {
return $img->Link(); return $img->Link();
} }
@ -69,8 +70,8 @@ class SlideImageEx extends DataExtension
public function getSlideWidth() public function getSlideWidth()
{ {
$element = $this->getElement(); $element = $this->getElement();
if(!$element->ID) { if (!$element->ID) {
return SliderElement::config()->get('slide_width'); return SliderElement::config()->get('slide_width');
} }
return $element->getSlideWidth(); return $element->getSlideWidth();
@ -79,8 +80,8 @@ class SlideImageEx extends DataExtension
public function getSlideHeight() public function getSlideHeight()
{ {
$element = $this->getElement(); $element = $this->getElement();
if(!$element->ID) { if (!$element->ID) {
return SliderElement::config()->get('slide_height'); return SliderElement::config()->get('slide_height');
} }
return $element->getSlideHeight(); return $element->getSlideHeight();

View File

@ -1,5 +1,10 @@
<% if $Video || $Image %> <% if $Video || $Image %>
<% if $Video %> <% if $VideoFile %>
<video controls="controls">
<source src="{$VideoFile.Link}" type="video/mp4" />
Your browser does not support the video tag.
</video>
<% else_if $Video %>
<div class="video"> <div class="video">
$Video.EmbedHTML.RAW $Video.EmbedHTML.RAW
</div> </div>