|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class SlideImage extends DataObject implements PermissionProvider |
|
4
|
|
|
{ |
|
5
|
|
|
//TODO: move to config.yml |
|
6
|
|
|
private static $defaults = array( |
|
|
|
|
|
|
7
|
|
|
'ShowSlide' => true, |
|
8
|
|
|
); |
|
9
|
|
|
|
|
10
|
1 |
|
public function getCMSFields() |
|
|
|
|
|
|
11
|
|
|
{ |
|
12
|
1 |
|
$fields = parent::getCMSFields(); |
|
13
|
1 |
|
$ImageField = new UploadField('Image', 'Image'); |
|
14
|
1 |
|
$ImageField->getValidator()->allowedExtensions = array('jpg', 'jpeg', 'gif', 'png'); |
|
15
|
1 |
|
$ImageField->setFolderName('Uploads/SlideImages'); |
|
16
|
1 |
|
$ImageField->setConfig('allowedMaxFileNumber', 1); |
|
17
|
1 |
|
$ImageField->getValidator()->setAllowedMaxFileSize(FLEXSLIDER_IMAGE_FILE_SIZE_LIMIT); |
|
18
|
|
|
|
|
19
|
1 |
|
$fields->removeByName(array('ShowSlide')); |
|
20
|
|
|
|
|
21
|
1 |
|
$fields->addFieldsToTab('Root.Main', array( |
|
22
|
1 |
|
TextField::create('Name') |
|
23
|
1 |
|
->setDescription('for internal reference only'), |
|
24
|
1 |
|
TextField::create('Title') |
|
25
|
1 |
|
->setDescription('optional, used in template'), |
|
26
|
1 |
|
TextareaField::create('Description') |
|
27
|
1 |
|
->setDescription('optional, used in template'), |
|
28
|
1 |
|
TreeDropdownField::create('PageLinkID', 'Choose a page to link to:', 'SiteTree'), |
|
29
|
1 |
|
$ImageField, |
|
30
|
1 |
|
CheckboxField::create('ShowSlide')->setTitle('Show Slide') |
|
31
|
1 |
|
->setDescription('Include this slide in the slider. Uncheck to hide'), |
|
32
|
1 |
|
)); |
|
33
|
1 |
|
$fields->removeByName(array( |
|
34
|
1 |
|
'SortOrder', |
|
35
|
1 |
|
'PageID', |
|
36
|
1 |
|
)); |
|
37
|
|
|
|
|
38
|
1 |
|
$this->extend('updateCMSFields', $fields); |
|
39
|
|
|
|
|
40
|
1 |
|
return $fields; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
6 |
|
public function validate() |
|
44
|
|
|
{ |
|
45
|
6 |
|
$result = parent::validate(); |
|
46
|
|
|
|
|
47
|
6 |
|
if (!$this->Name) { |
|
|
|
|
|
|
48
|
1 |
|
$result->error('A Name is required before you can save'); |
|
49
|
1 |
|
} |
|
50
|
|
|
|
|
51
|
6 |
|
if (!$this->ImageID) { |
|
|
|
|
|
|
52
|
2 |
|
$result->error('An Image is required before you can save'); |
|
53
|
2 |
|
} |
|
54
|
|
|
|
|
55
|
6 |
|
return $result; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
1 |
|
public function providePermissions() |
|
59
|
|
|
{ |
|
60
|
|
|
return array( |
|
61
|
1 |
|
'Slide_EDIT' => 'Slide Edit', |
|
62
|
1 |
|
'Slide_DELETE' => 'Slide Delete', |
|
63
|
1 |
|
'Slide_CREATE' => 'Slide Create', |
|
64
|
1 |
|
); |
|
65
|
|
|
} |
|
66
|
1 |
|
public function canCreate($member = null) |
|
67
|
|
|
{ |
|
68
|
1 |
|
return Permission::check('Slide_CREATE'); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
1 |
|
public function canEdit($member = null) |
|
72
|
|
|
{ |
|
73
|
1 |
|
return Permission::check('Slide_EDIT'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
1 |
|
public function canDelete($member = null) |
|
77
|
|
|
{ |
|
78
|
1 |
|
return Permission::check('Slide_DELETE'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
1 |
|
public function canView($member = null) |
|
82
|
|
|
{ |
|
83
|
1 |
|
return true; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.