Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REFACTOR Augment Slide models #32

Merged
merged 5 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/Model/ImageSlide.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

use SilverStripe\Assets\Image;
use SilverStripe\Forms\FieldList;
use SilverStripe\LinkField\Form\LinkField;
use SilverStripe\LinkField\Models\Link;
use SilverStripe\LinkField\Form\LinkField;
use SilverStripe\AssetAdmin\Forms\UploadField;

/**
* Class \Dynamic\Carousel\Model\ImageSlide
Expand Down Expand Up @@ -40,6 +41,7 @@ class ImageSlide extends Slide
*/
private static $has_one = [
'Image' => Image::class,
'ImageMobile' => Image::class,
'ElementLink' => Link::class,
];

Expand All @@ -49,6 +51,7 @@ class ImageSlide extends Slide
*/
private static $owns = [
'Image',
'ImageMobile',
'ElementLink',
];

Expand Down Expand Up @@ -82,6 +85,7 @@ public function getCMSFields(): FieldList
$link = LinkField::create('ElementLink')
->setTitle($this->fieldLabel('ElementLink'))
);
$link->setDescription('Optional. Leave blank to hide.');

$fields->addFieldsToTab(
'Root.Main',
Expand All @@ -93,6 +97,21 @@ public function getCMSFields(): FieldList
],
'Content'
);

// Image for small screens
$fields->insertAfter(
'Image',
UploadField::create('ImageMobile', 'Image (for small screens)')
->setFolderName('Uploads/Carousel/Slides')
->setDescription('Optional.')
);

if (
$this->getOwner()->hasField('ParentID') &&
$this->getOwner()->Parent() instanceof \SilverStripe\CMS\Model\SiteTree
) {
$fields->dataFieldByName('Image')->setDescription('Recommended size: 1920x823');
}
});

return parent::getCMSFields();
Expand Down
10 changes: 10 additions & 0 deletions src/Model/Slide.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ public function getCMSFields(): FieldList
return parent::getCMSFields();
}

/**
* ShowCaption
*/
public function ShowCaption(): bool
{
$owner = $this->getOwner();

return (($owner->Title && $owner->ShowTitle) || $owner->SubTitle || $owner->Content);
}

/**
* Basic permissions, defaults to parent perms where possible.
*
Expand Down
33 changes: 32 additions & 1 deletion src/Model/VideoSlide.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

use SilverStripe\Assets\File;
use SilverStripe\Forms\FieldList;
use nathancox\EmbedField\Forms\EmbedField;
use nathancox\EmbedField\Model\EmbedObject;
use UncleCheese\DisplayLogic\Forms\Wrapper;
use SilverStripe\AssetAdmin\Forms\UploadField;

/**
* Class \Dynamic\Carousel\Model\VideoSlide
Expand Down Expand Up @@ -41,6 +45,7 @@ class VideoSlide extends Slide
*/
private static $has_one = [
'Video' => File::class,
'EmbedVideo' => EmbedObject::class,
];

/**
Expand All @@ -56,7 +61,33 @@ class VideoSlide extends Slide
public function getCMSFields(): FieldList
{
$this->beforeUpdateCMSFields(function (FieldList $fields) {
//$fields->
// Remvove fields
$fields->removeByName([
'EmbedVideoID',
'Video',
]);

// Native video
$uploadVideo = UploadField::create('Video', 'Upload video')
->setFolderName('Uploads/Carousel/Videos');

$fields->insertAfter(
'VideoType',
$uploadVideo
);

// Embed video
// @phpstan-ignore class.notFound
$embedVideo = Wrapper::create(EmbedField::create('EmbedVideoID', 'Embed video'));

$fields->insertAfter(
'VideoType',
$embedVideo
);

//
$uploadVideo->displayIf("VideoType")->isEqualTo("Native");
$embedVideo->displayIf("VideoType")->isEqualTo("Embed");
});

return parent::getCMSFields();
Expand Down
Loading