diff --git a/app/src/Elements/SliderElement.php b/app/src/Elements/SliderElement.php index f9e637a..d9f8a57 100644 --- a/app/src/Elements/SliderElement.php +++ b/app/src/Elements/SliderElement.php @@ -24,10 +24,13 @@ class SliderElement extends ElementSlideshow private static $plural_name = 'Sliders'; - private static $description = 'Displays slideshow'; + private static $description = 'Displays slide show'; private static $table_name = 'SliderElement'; + private static $slide_width = 2140; + private static $slide_height = 700; + private static $db = [ 'Interval' => 'Int', ]; @@ -47,6 +50,16 @@ class SliderElement extends ElementSlideshow return self::$singular_name; } + public function getSlideWidth() + { + return self::config()->get('slide_width'); + } + + public function getSlideHeight() + { + return self::config()->get('slide_height'); + } + public function getCMSFields() { $fields = parent::getCMSFields(); @@ -71,17 +84,17 @@ class SliderElement extends ElementSlideshow $grid = $fields->dataFieldByName('Slides'); if ($grid) { - $config = $grid->getConfig(); + $config = $grid->getConfig(); - $columns = new GridFieldEditableColumns(); - $columns->setDisplayFields([ + $columns = new GridFieldEditableColumns(); + $columns->setDisplayFields([ 'Hide' => [ 'title' => 'Hide it?', 'field' => CheckboxField::class, ], ]); - $config->addComponent($columns); + $config->addComponent($columns); } return $fields; @@ -92,14 +105,14 @@ class SliderElement extends ElementSlideshow */ public function getSlideShow() { - if($this->items) { + if ($this->items) { return $this->items; } $date = date('Y-m-d H:i:s'); $this->items = $this->Slides()->filter([ 'Hide' => '0', - ])->filterByCallback(function($item, $list) use ($date) { + ])->filterByCallback(static function ($item, $list) use ($date) { $on = $item->getField('DateOn'); $off = $item->getField('DateOff'); @@ -113,7 +126,7 @@ class SliderElement extends ElementSlideshow { parent::onBeforeWrite(); - if(!$this->getField('Interval')){ + if (!$this->getField('Interval')) { $this->setField('Interval', 5000); } } diff --git a/app/src/Extensions/SlideImageExtension.php b/app/src/Extensions/SlideImageExtension.php index 32f10ea..212044e 100644 --- a/app/src/Extensions/SlideImageExtension.php +++ b/app/src/Extensions/SlideImageExtension.php @@ -4,16 +4,14 @@ * User: tony * Date: 6/30/18 * Time: 11:37 PM + * Ref: Dynamic\FlexSlider\Model\SlideImage */ namespace Site\Extensions; -use Sheadawson\Linkable\Forms\LinkField; -use Sheadawson\Linkable\Models\Link; use SilverStripe\Forms\CheckboxField; use SilverStripe\Forms\DatetimeField; use SilverStripe\Forms\FieldList; -use SilverStripe\Forms\TextField; use SilverStripe\Forms\ToggleCompositeField; use SilverStripe\ORM\DataExtension; @@ -25,6 +23,29 @@ class SlideImageExtension extends DataExtension 'DateOff' => 'Datetime', ]; + private $_cache = []; + + public function getElement() + { + if(!isset($this->_cache['element'])) { + $this->_cache['element'] = $this->owner->SlideshowElement(); + } + + return $this->_cache['element']; + } + + public function getSlideWidth() + { + $element = $this->getElement(); + return $element->getSlideWidth(); + } + + public function getSlideHeight() + { + $element = $this->getElement(); + return $element->getSlideHeight(); + } + public function updateCMSFields(FieldList $fields) { parent::updateCMSFields($fields); @@ -36,9 +57,14 @@ class SlideImageExtension extends DataExtension 'DateOff', ]); + + $fields->dataFieldByName('Image') + ->setTitle('Image ('.$this->getSlideWidth().' x '.$this->getSlideHeight().' px)'); + $fields->addFieldToTab('Root.Main', ToggleCompositeField::create( 'ConfigHD', - 'Slide Settings', [ + 'Slide Settings', + [ CheckboxField::create('Hide', 'Hide this slide? (That will hide the slide regardless of start/end fields)'), DatetimeField::create('DateOn', 'When would you like to start showing the slide?'), DatetimeField::create('DateOff', 'When would you like to stop showing the slide?'), diff --git a/app/templates/Includes/SlideItem.ss b/app/templates/Includes/SlideItem.ss index cf3d8f6..2b46146 100644 --- a/app/templates/Includes/SlideItem.ss +++ b/app/templates/Includes/SlideItem.ss @@ -8,7 +8,7 @@ <% if $Headline %>$Headline.XML<% end_if %>