mirror of
https://github.com/a2nt/silverstripe-webpack.git
synced 2024-10-22 17:05:31 +02:00
Slider improvements on/off/hide fields
This commit is contained in:
parent
7dfa727298
commit
f7faea28a5
@ -11,6 +11,10 @@ SilverStripe\Blog\Model\BlogPost:
|
|||||||
extensions:
|
extensions:
|
||||||
- Site\Extensions\BlogPostExtension
|
- Site\Extensions\BlogPostExtension
|
||||||
|
|
||||||
|
Dynamic\FlexSlider\Model\SlideImage:
|
||||||
|
extensions:
|
||||||
|
- Site\Extensions\SlideImageExtension
|
||||||
|
|
||||||
SilverStripe\Core\Injector\Injector:
|
SilverStripe\Core\Injector\Injector:
|
||||||
SilverStripe\UserForms\Model\UserDefinedForm:
|
SilverStripe\UserForms\Model\UserDefinedForm:
|
||||||
class: Site\Extensions\CMSMain_HiddenClass
|
class: Site\Extensions\CMSMain_HiddenClass
|
||||||
|
@ -9,7 +9,13 @@
|
|||||||
namespace Site\Elements;
|
namespace Site\Elements;
|
||||||
|
|
||||||
use Dynamic\Elements\Flexslider\Elements\ElementSlideshow;
|
use Dynamic\Elements\Flexslider\Elements\ElementSlideshow;
|
||||||
|
use Dynamic\FlexSlider\Model\SlideImage;
|
||||||
use Dynamic\FlexSlider\ORM\FlexSlider;
|
use Dynamic\FlexSlider\ORM\FlexSlider;
|
||||||
|
use SilverStripe\Core\Injector\Injector;
|
||||||
|
use SilverStripe\Forms\CheckboxField;
|
||||||
|
use SilverStripe\Forms\LiteralField;
|
||||||
|
use SilverStripe\Forms\ReadonlyField;
|
||||||
|
use Symbiote\GridFieldExtensions\GridFieldEditableColumns;
|
||||||
|
|
||||||
class SliderElement extends ElementSlideshow
|
class SliderElement extends ElementSlideshow
|
||||||
{
|
{
|
||||||
@ -25,8 +31,70 @@ class SliderElement extends ElementSlideshow
|
|||||||
FlexSlider::class,
|
FlexSlider::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
private static $owns = [
|
||||||
|
'Slides',
|
||||||
|
];
|
||||||
|
|
||||||
|
private $items;
|
||||||
|
|
||||||
public function getType()
|
public function getType()
|
||||||
{
|
{
|
||||||
return self::$singular_name;
|
return self::$singular_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCMSFields()
|
||||||
|
{
|
||||||
|
$fields = parent::getCMSFields();
|
||||||
|
|
||||||
|
// remove in case you don't need to provide this functionality
|
||||||
|
$fields->removeByName([
|
||||||
|
'ConfigHD',
|
||||||
|
'Animation',
|
||||||
|
'Loop',
|
||||||
|
'Animate',
|
||||||
|
'ThumbnailNav',
|
||||||
|
'SliderControlNav',
|
||||||
|
'SliderDirectionNav',
|
||||||
|
'CarouselControlNav',
|
||||||
|
'CarouselDirectionNav',
|
||||||
|
'CarouselThumbnailCt',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$grid = $fields->dataFieldByName('Slides');
|
||||||
|
$config = $grid->getConfig();
|
||||||
|
|
||||||
|
$columns = new GridFieldEditableColumns();
|
||||||
|
$columns->setDisplayFields([
|
||||||
|
'Hide' => [
|
||||||
|
'title' => 'Hide it?',
|
||||||
|
'field' => CheckboxField::class,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$config->addComponent($columns);
|
||||||
|
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getSlideShow()
|
||||||
|
{
|
||||||
|
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) {
|
||||||
|
$on = $item->getField('DateOn');
|
||||||
|
$off = $item->getField('DateOff');
|
||||||
|
|
||||||
|
return ($on <= $date) && (!$off || $off > $date);
|
||||||
|
})->sort('SortOrder');
|
||||||
|
|
||||||
|
return $this->items;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
48
app/src/Extensions/SlideImageExtension.php
Normal file
48
app/src/Extensions/SlideImageExtension.php
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: tony
|
||||||
|
* Date: 6/30/18
|
||||||
|
* Time: 11:37 PM
|
||||||
|
*/
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
class SlideImageExtension extends DataExtension
|
||||||
|
{
|
||||||
|
private static $db = [
|
||||||
|
'Hide' => 'Boolean(0)',
|
||||||
|
'DateOn' => 'Datetime',
|
||||||
|
'DateOff' => 'Datetime',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function updateCMSFields(FieldList $fields)
|
||||||
|
{
|
||||||
|
parent::updateCMSFields($fields);
|
||||||
|
|
||||||
|
$fields->removeByName([
|
||||||
|
'PageLinkID',
|
||||||
|
'Hide',
|
||||||
|
'DateOn',
|
||||||
|
'DateOff',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$fields->addFieldToTab('Root.Main', ToggleCompositeField::create(
|
||||||
|
'ConfigHD',
|
||||||
|
'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?'),
|
||||||
|
]
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user