2008-09-29 03:18:23 +00:00
|
|
|
<?php
|
2012-04-14 18:36:50 +12:00
|
|
|
|
2008-09-29 03:18:23 +00:00
|
|
|
/**
|
2012-04-14 18:36:50 +12:00
|
|
|
* Allows a user to add a field that can be used to upload a file.
|
2009-04-17 02:26:40 +00:00
|
|
|
*
|
|
|
|
* @package userforms
|
2008-09-29 03:18:23 +00:00
|
|
|
*/
|
2009-12-07 02:04:20 +00:00
|
|
|
|
2008-09-29 03:18:23 +00:00
|
|
|
class EditableFileField extends EditableFormField {
|
|
|
|
|
2013-04-02 18:34:43 -07:00
|
|
|
private static $singular_name = 'File Upload Field';
|
2013-03-05 10:45:54 +13:00
|
|
|
|
2013-04-02 18:34:43 -07:00
|
|
|
private static $plural_names = 'File Fields';
|
2013-12-20 21:07:35 +13:00
|
|
|
|
|
|
|
public function getFieldConfiguration() {
|
|
|
|
$field = parent::getFieldConfiguration();
|
|
|
|
$folder = ($this->getSetting('Folder')) ? $this->getSetting('Folder') : null;
|
|
|
|
|
|
|
|
$tree = UserformsTreeDropdownField::create(
|
|
|
|
$this->getSettingName("Folder"),
|
|
|
|
_t('EditableUploadField.SELECTUPLOADFOLDER', 'Select upload folder'),
|
|
|
|
"Folder"
|
|
|
|
);
|
|
|
|
|
|
|
|
$tree->setValue($folder);
|
|
|
|
|
|
|
|
$field->push($tree);
|
|
|
|
|
|
|
|
return $field;
|
|
|
|
}
|
|
|
|
|
2009-04-27 04:32:47 +00:00
|
|
|
public function getFormField() {
|
2014-12-22 12:19:33 +10:30
|
|
|
$field = FileField::create($this->Name, $this->Title);
|
2012-04-14 18:36:50 +12:00
|
|
|
|
2015-07-16 09:23:43 +12:00
|
|
|
// filter out '' since this would be a regex problem on JS end
|
|
|
|
$field->getValidator()->setAllowedExtensions(
|
|
|
|
array_filter(Config::inst()->get('File', 'allowed_extensions'))
|
|
|
|
);
|
|
|
|
|
2013-12-20 21:07:35 +13:00
|
|
|
if($this->getSetting('Folder')) {
|
|
|
|
$folder = Folder::get()->byId($this->getSetting('Folder'));
|
|
|
|
|
|
|
|
if($folder) {
|
|
|
|
$field->setFolderName(
|
|
|
|
preg_replace("/^assets\//","", $folder->Filename)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-22 12:19:33 +10:30
|
|
|
if ($this->Required) {
|
|
|
|
// Required validation can conflict so add the Required validation messages
|
|
|
|
// as input attributes
|
|
|
|
$errorMessage = $this->getErrorMessage()->HTML();
|
|
|
|
$field->setAttribute('data-rule-required', 'true');
|
|
|
|
$field->setAttribute('data-msg-required', $errorMessage);
|
|
|
|
}
|
|
|
|
|
2012-04-14 18:36:50 +12:00
|
|
|
return $field;
|
2008-09-29 03:18:23 +00:00
|
|
|
}
|
2009-04-28 02:03:13 +00:00
|
|
|
|
2012-04-14 18:36:50 +12:00
|
|
|
|
2014-04-25 09:53:45 -04:00
|
|
|
/**
|
|
|
|
* Return the value for the database, link to the file is stored as a
|
|
|
|
* relation so value for the field can be null.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getValueFromData() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2010-02-14 07:53:16 +00:00
|
|
|
public function getSubmittedFormField() {
|
|
|
|
return new SubmittedFileField();
|
2012-04-14 18:36:50 +12:00
|
|
|
}
|
2013-12-20 21:07:35 +13:00
|
|
|
}
|