IMPROVEMENT: customize slide image size

This commit is contained in:
Tony Air 2020-02-13 03:41:09 +07:00
parent d52c250076
commit 918cf66907
3 changed files with 52 additions and 13 deletions

View File

@ -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);
}
}

View File

@ -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?'),

View File

@ -8,7 +8,7 @@
<span class="img">
<img class="d-block w-100"
src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
data-lazy-src="<% if $ImageURL %>$ImageURL<% else %>$Image.Fill(1400,650).URL<% end_if %>"
data-lazy-src="<% if $ImageURL %>$ImageURL<% else %>$Image.Fill($SlideWidth,$SlideHeight).URL<% end_if %>"
alt="<% if $Headline %>$Headline.XML<% end_if %>"
/>
</span>