1 | <?php |
||
8 | class EditableFileField extends EditableFormField |
||
|
|||
9 | { |
||
10 | |||
11 | private static $singular_name = 'File Upload Field'; |
||
12 | |||
13 | private static $plural_names = 'File Fields'; |
||
14 | |||
15 | private static $db = array( |
||
16 | 'MaxFileSizeMB' => 'Float', |
||
17 | ); |
||
18 | |||
19 | private static $has_one = array( |
||
20 | 'Folder' => 'Folder' // From CustomFields |
||
21 | ); |
||
22 | |||
23 | /** |
||
24 | * Further limit uploadable file extensions in addition to the restrictions |
||
25 | * imposed by the File.allowed_extensions global configuration. |
||
26 | * @config |
||
27 | */ |
||
28 | private static $allowed_extensions_blacklist = array( |
||
29 | 'htm', 'html', 'xhtml', 'swf', 'xml' |
||
30 | ); |
||
31 | |||
32 | /** |
||
33 | * @return FieldList |
||
34 | */ |
||
35 | public function getCMSFields() |
||
62 | |||
63 | /** |
||
64 | * @return ValidationResult |
||
65 | */ |
||
66 | 6 | public function validate() |
|
77 | |||
78 | 4 | public function getFormField() |
|
79 | { |
||
80 | 4 | $field = FileField::create($this->Name, $this->EscapedTitle) |
|
81 | 4 | ->setFieldHolderTemplate('UserFormsField_holder') |
|
82 | 4 | ->setTemplate('UserFormsFileField'); |
|
83 | |||
84 | 4 | $field->setFieldHolderTemplate('UserFormsField_holder') |
|
85 | 4 | ->setTemplate('UserFormsFileField'); |
|
86 | |||
87 | 4 | $field->getValidator()->setAllowedExtensions( |
|
88 | 4 | array_diff( |
|
89 | // filter out '' since this would be a regex problem on JS end |
||
90 | 4 | array_filter(Config::inst()->get('File', 'allowed_extensions')), |
|
91 | 4 | $this->config()->allowed_extensions_blacklist |
|
92 | 4 | ) |
|
93 | 4 | ); |
|
94 | |||
95 | 4 | if ($this->MaxFileSizeMB > 0) { |
|
96 | 1 | $field->getValidator()->setAllowedMaxFileSize($this->MaxFileSizeMB * 1024); |
|
97 | 1 | } else { |
|
98 | 3 | $field->getValidator()->setAllowedMaxFileSize(static::get_php_max_file_size()); |
|
99 | } |
||
100 | |||
101 | 4 | $folder = $this->Folder(); |
|
102 | 4 | if ($folder && $folder->exists()) { |
|
103 | 4 | $field->setFolderName( |
|
104 | 4 | preg_replace("/^assets\//", "", $folder->Filename) |
|
105 | 4 | ); |
|
106 | 4 | } |
|
107 | |||
108 | 4 | $this->doUpdateFormField($field); |
|
109 | |||
110 | 4 | return $field; |
|
111 | } |
||
112 | |||
113 | |||
114 | /** |
||
115 | * Return the value for the database, link to the file is stored as a |
||
116 | * relation so value for the field can be null. |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | public function getValueFromData() |
||
124 | |||
125 | public function getSubmittedFormField() |
||
129 | |||
130 | |||
131 | 2 | public function migrateSettings($data) |
|
141 | |||
142 | /** |
||
143 | * @return float |
||
144 | */ |
||
145 | 9 | public static function get_php_max_file_size() |
|
151 | |||
152 | 1 | public function getPHPMaxFileSizeMB() |
|
156 | |||
157 | } |
||
158 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.