1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DorsetDigital\Elements\PhotoSwipe\Models; |
4
|
|
|
|
5
|
|
|
use Bummzack\SortableFile\Forms\SortableUploadField; |
6
|
|
|
use DNADesign\Elemental\Models\BaseElement; |
7
|
|
|
use DorsetDigital\Elements\PhotoSwipe\Controllers\GalleryController; |
8
|
|
|
use SilverStripe\Assets\Image; |
9
|
|
|
use SilverStripe\i18n\i18n; |
10
|
|
|
use SilverStripe\Security\Security; |
11
|
|
|
use SilverStripe\View\SSViewer; |
12
|
|
|
|
13
|
|
|
class Gallery extends BaseElement |
14
|
|
|
{ |
15
|
|
|
private static $singular_name = 'Photoswipe Gallery'; |
16
|
|
|
private static $plural_name = 'Photoswipe Galleries'; |
17
|
|
|
private static $description = 'Responsive image gallery'; |
18
|
|
|
private static $table_name = 'DorsetDigital_Elements_PhotoSwipe'; |
19
|
|
|
private static $controller_class = GalleryController::class; |
20
|
|
|
|
21
|
|
|
private static $inline_editable = false; |
22
|
|
|
|
23
|
|
|
private static $casting = [ |
24
|
|
|
'getSummary' => 'HTMLText' |
25
|
|
|
]; |
26
|
|
|
|
27
|
|
|
private static $many_many = [ |
28
|
|
|
'GalleryImages' => Image::class |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
private static $many_many_extraFields = [ |
32
|
|
|
'GalleryImages' => [ |
33
|
|
|
'SortOrder' => 'Int' |
34
|
|
|
] |
35
|
|
|
]; |
36
|
|
|
|
37
|
|
|
private static $owns = [ |
38
|
|
|
'GalleryImages' |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
public function getCMSFields() |
42
|
|
|
{ |
43
|
|
|
$fields = parent::getCMSFields(); |
44
|
|
|
$fields->addFieldToTab('Root.Main', SortableUploadField::create( |
45
|
|
|
'GalleryImages', $this->owner->fieldLabel('Images') |
46
|
|
|
)->setFolderName('galleryimages')->setAllowedFileCategories('image/supported')); |
47
|
|
|
return $fields; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function getSortedImages() |
51
|
|
|
{ |
52
|
|
|
return $this->GalleryImages()->sort('SortOrder'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getType() |
56
|
|
|
{ |
57
|
|
|
return 'Photoswipe Gallery'; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
protected function provideBlockSchema() |
61
|
|
|
{ |
62
|
|
|
$blockSchema = parent::provideBlockSchema(); |
63
|
|
|
$blockSchema['content'] = $this->getSummary(); |
64
|
|
|
return $blockSchema; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getSummary() |
68
|
|
|
{ |
69
|
|
|
return i18n::with_locale(Security::getCurrentUser()->Locale, function () { |
70
|
|
|
$template = SSViewer::get_templates_by_class(static::class, '_Summary'); |
71
|
|
|
$summary = $this->renderWith($template); |
72
|
|
|
return $summary->RAW(); |
73
|
|
|
}); |
74
|
|
|
} |
75
|
|
|
} |