mirror of
https://github.com/a2nt/silverstripe-elemental-basics.git
synced 2024-10-22 17:05:54 +02:00
IMPR: Original image size option
This commit is contained in:
parent
6cbf5ea662
commit
367c33939c
@ -36,6 +36,7 @@ class SliderElement extends ElementSlideshow
|
||||
private static $db = [
|
||||
'Interval' => 'Int',
|
||||
'SlidesInRow' => 'Int',
|
||||
'ImageOriginalSize' => 'Boolean(0)',
|
||||
];
|
||||
|
||||
private static $extensions = [
|
||||
@ -53,14 +54,28 @@ class SliderElement extends ElementSlideshow
|
||||
return self::$singular_name;
|
||||
}
|
||||
|
||||
protected function ratioSize($size)
|
||||
{
|
||||
$count = $this->SlidesInRow;
|
||||
return ($count > 1) ? $size / $count : $size;
|
||||
}
|
||||
|
||||
public function getSlideWidth()
|
||||
{
|
||||
return self::config()->get('slide_width');
|
||||
if($this->getField('ImageOriginalSize')){
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->ratioSize(self::config()->get('slide_width'));
|
||||
}
|
||||
|
||||
public function getSlideHeight()
|
||||
{
|
||||
return self::config()->get('slide_height');
|
||||
if($this->getField('ImageOriginalSize')){
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->ratioSize(self::config()->get('slide_height'));
|
||||
}
|
||||
|
||||
public function getCMSFields()
|
||||
@ -82,6 +97,7 @@ class SliderElement extends ElementSlideshow
|
||||
]);
|
||||
|
||||
$fields->addFieldsToTab('Root.Settings', [
|
||||
CheckboxField::create('ImageOriginalSize', 'Use original image size'),
|
||||
NumericField::create('Interval', 'Auto-play Interval (sec)'),
|
||||
NumericField::create('SlidesInRow'),
|
||||
]);
|
||||
|
@ -10,6 +10,9 @@ namespace A2nt\ElementalBasics\Extensions;
|
||||
|
||||
use DNADesign\Elemental\Models\BaseElement;
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Forms\CheckboxField;
|
||||
use SilverStripe\Forms\DatetimeField;
|
||||
use SilverStripe\Forms\ToggleCompositeField;
|
||||
use SilverStripe\Forms\TreeDropdownField;
|
||||
use SilverStripe\ORM\DataExtension;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
@ -18,6 +21,88 @@ use SilverStripe\ORM\ValidationResult;
|
||||
|
||||
class SlideImageEx extends DataExtension
|
||||
{
|
||||
private static $db = [
|
||||
'Hide' => 'Boolean(0)',
|
||||
'DateOn' => 'Datetime',
|
||||
'DateOff' => 'Datetime',
|
||||
];
|
||||
|
||||
private $_cache = [
|
||||
'element' => [],
|
||||
];
|
||||
|
||||
public function getElement()
|
||||
{
|
||||
if(!isset($this->_cache['element'][$this->owner->ID])) {
|
||||
$this->_cache['element'][$this->owner->ID] = $this->owner->SlideshowElement();
|
||||
}
|
||||
|
||||
return $this->_cache['element'][$this->owner->ID];
|
||||
}
|
||||
|
||||
|
||||
public function ImageURL()
|
||||
{
|
||||
$el = $this->getElement();
|
||||
$img = $this->owner->Image();
|
||||
|
||||
if(!$img) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if($el->getField('ImageOriginalSize')){
|
||||
return $img->Link();
|
||||
}
|
||||
|
||||
return $img->FocusFill($this->getSlideWidth(), $this->getSlideHeight())->Link();
|
||||
}
|
||||
|
||||
public function getSlideWidth()
|
||||
{
|
||||
$element = $this->getElement();
|
||||
if(!$element->ID) {
|
||||
return SliderElement::config()->get('slide_width');
|
||||
}
|
||||
|
||||
return $element->getSlideWidth();
|
||||
}
|
||||
|
||||
public function getSlideHeight()
|
||||
{
|
||||
$element = $this->getElement();
|
||||
if(!$element->ID) {
|
||||
return SliderElement::config()->get('slide_height');
|
||||
}
|
||||
|
||||
return $element->getSlideHeight();
|
||||
}
|
||||
|
||||
public function updateCMSFields(FieldList $fields)
|
||||
{
|
||||
parent::updateCMSFields($fields);
|
||||
|
||||
$fields->removeByName([
|
||||
'PageLinkID',
|
||||
'Hide',
|
||||
'DateOn',
|
||||
'DateOff',
|
||||
]);
|
||||
|
||||
|
||||
$fields->dataFieldByName('Image')
|
||||
->setTitle('Image ('.$this->getSlideWidth().' x '.$this->getSlideHeight().' px)');
|
||||
|
||||
$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?'),
|
||||
]
|
||||
));
|
||||
}
|
||||
|
||||
public function validate(ValidationResult $validationResult)
|
||||
{
|
||||
if (!$this->owner->Name) {
|
||||
|
Loading…
Reference in New Issue
Block a user