Skip to content

Commit

Permalink
Merge branch '5.7' into 5
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Nov 12, 2020
2 parents 6df5397 + ead1827 commit f81360e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions _config/mimevalidator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
Name: mimeuploadvalidator-userforms
---
SilverStripe\Core\Injector\Injector:
SilverStripe\Assets\Upload_Validator.userforms:
class: SilverStripe\MimeValidator\MimeUploadValidator
9 changes: 7 additions & 2 deletions code/Model/EditableFormField/EditableFileField.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

use SilverStripe\Assets\File;
use SilverStripe\Assets\Folder;
use SilverStripe\Assets\Upload_Validator;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Convert;
use SilverStripe\Forms\FieldList;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\FileField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\NumericField;
Expand Down Expand Up @@ -185,18 +187,21 @@ public function validate()
$result = parent::validate();

$max = static::get_php_max_file_size();
if ($this->MaxFileSizeMB * 1024 > $max) {
if ($this->MaxFileSizeMB * 1024 * 1024 > $max) {
$result->addError("Your max file size limit can't be larger than the server's limit of {$this->getPHPMaxFileSizeMB()}.");
}

return $result;
}



public function getFormField()
{
$field = FileField::create($this->Name, $this->Title ?: false)
->setFieldHolderTemplate(EditableFormField::class . '_holder')
->setTemplate(__CLASS__);
->setTemplate(__CLASS__)
->setValidator(Injector::inst()->get(Upload_Validator::class . '.userforms'));

$field->setFieldHolderTemplate(EditableFormField::class . '_holder')
->setTemplate(__CLASS__);
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"silverstripe/cms": "^4.6",
"symbiote/silverstripe-gridfieldextensions": "^3.1",
"silverstripe/segment-field": "^2.0",
"silverstripe/versioned": "^1.0"
"silverstripe/versioned": "^1.0",
"silverstripe/mimevalidator": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
Expand Down

0 comments on commit f81360e

Please sign in to comment.