1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\ProductCatalog\Docs; |
4
|
|
|
|
5
|
|
|
use SilverStripe\AssetAdmin\Forms\UploadField; |
6
|
|
|
use SilverStripe\Assets\File; |
7
|
|
|
use SilverStripe\Assets\Image; |
8
|
|
|
use SilverStripe\Forms\TextField; |
9
|
|
|
use SilverStripe\ORM\DataObject; |
10
|
|
|
|
11
|
|
|
class ProductDoc extends DataObject |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var array |
15
|
|
|
*/ |
16
|
|
|
private static $db = array( |
|
|
|
|
17
|
|
|
'Name' => 'Varchar(255)', |
18
|
|
|
'Title' => 'Varchar(255)', |
19
|
|
|
'Content' => 'HTMLText', |
20
|
|
|
'FileLink' => 'Varchar(255)', |
21
|
|
|
); |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
private static $has_one = array( |
|
|
|
|
27
|
|
|
'Image' => Image::class, |
28
|
|
|
'Download' => File::class, |
29
|
|
|
); |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
private static $table_name = 'ProductDoc'; |
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var array |
38
|
|
|
*/ |
39
|
|
|
private static $summary_fields = array( |
|
|
|
|
40
|
|
|
'Name' => 'Name', |
41
|
|
|
'Title' => 'Title', |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var array |
46
|
|
|
*/ |
47
|
|
|
private static $searchable_fields = array( |
|
|
|
|
48
|
|
|
'Name', |
49
|
|
|
'Title', |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var string |
54
|
|
|
*/ |
55
|
|
|
private static $default_sort = 'Title'; |
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return \SilverStripe\Forms\FieldList |
59
|
|
|
*/ |
60
|
6 |
|
public function getCMSFields() |
61
|
|
|
{ |
62
|
6 |
|
$fields = parent::getCMSFields(); |
63
|
|
|
|
64
|
6 |
|
$fields->removeByName([ |
65
|
6 |
|
'Products', |
66
|
|
|
]); |
67
|
|
|
|
68
|
6 |
|
$file = UploadField::create('Download') |
69
|
6 |
|
->setFolderName('Uploads/FileDownloads') |
70
|
|
|
//->setAllowedFileCategories('doc') |
71
|
|
|
; |
72
|
|
|
|
73
|
6 |
|
$fields->addFieldsToTab('Root.Download', array( |
74
|
6 |
|
$file, |
75
|
6 |
|
TextField::create('FileLink') |
76
|
6 |
|
->setDescription('URL of external file. will display on page if no Download is specified above.') |
77
|
6 |
|
->setAttribute('placeholder', 'http://'), |
78
|
|
|
)); |
79
|
|
|
|
80
|
6 |
|
$fields->insertBefore( |
81
|
6 |
|
UploadField::create('Image') |
82
|
|
|
//->setFolderName('Uploads/ProductDocs/Images') |
83
|
6 |
|
->setDescription('Preview image of file'), |
84
|
6 |
|
'Content' |
|
|
|
|
85
|
|
|
); |
86
|
|
|
|
87
|
6 |
|
return $fields; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* if SetClass dropdown is set, create a new instance of the new class. |
92
|
|
|
*/ |
93
|
10 |
|
public function onAfterWrite() |
94
|
|
|
{ |
95
|
10 |
|
parent::onAfterWrite(); |
96
|
10 |
|
if (isset($_REQUEST['SetClass'])) { |
97
|
|
|
$object = $this->newClassInstance($_REQUEST['SetClass']); |
98
|
|
|
$object->write(); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|