merged branch rdohms/upload-validation-details (PR #3637)
Commits -------836d12b
Fixing typo.ac2a187
Improved feedback for Upload Validator to cover all PHP error states. This way we don't get a unclear "upload error" message unless its something completely unexpected. Discussion ---------- Improved feedback for Upload Validator to cover all PHP error states. The upload validator only sets individual messages for 2 out of the 7 error states PHP suports for uploading files. Which means when you have any of those 5 stats you get a standard error message and have to really dig into the code to read the error state. I added messages for every state, so that you will always get a detailed message. --------------------------------------------------------------------------- by stloyd at 2012-03-19T13:54:04Z You should probably also extend translations in `FrameworkBundle`. --------------------------------------------------------------------------- by rdohms at 2012-03-19T14:04:50Z @stloyd what's the best way to do that? I obviously don't speak all languages. Could you point me to a best practices in this case? --------------------------------------------------------------------------- by stof at 2012-03-19T15:58:17Z @rdohms update the translations for the languages you speak. Other people will contribute with update later eventually :) --------------------------------------------------------------------------- by rdohms at 2012-03-19T22:34:50Z Fixed the typo, only other language i can update is portuguese, but it needs more work. I'll update it on a separate PR later on. Anything else for this PR? --------------------------------------------------------------------------- by mvrhov at 2012-03-20T05:41:00Z @rdohms: just put English strings into other lanugages --------------------------------------------------------------------------- by rdohms at 2012-03-20T07:35:56Z @mvrhov is there a quick way to do this? or is it copying and pasting into every language and adjusting the string IDs? --------------------------------------------------------------------------- by mvrhov at 2012-03-20T09:02:59Z AFAIK you'll have to copy paste. String ids and source are the same in all translations so it really is just c/p after you update the first one. --------------------------------------------------------------------------- by rdohms at 2012-03-20T09:56:48Z @mvrhov so which is the most updated one you would say? i see a lot of them missing bit and pieces :P --------------------------------------------------------------------------- by mvrhov at 2012-03-20T14:00:21Z Sorry no idea. --------------------------------------------------------------------------- by stof at 2012-03-20T19:09:10Z @mvrhov Please don't do this. The translation component has a fallback mecanism so putting the EN string in an incomplete translation file is a bad idea as it forbids using a fallback. --------------------------------------------------------------------------- by rdohms at 2012-03-20T20:14:50Z @stof i figured as much. Any other concerns before we push this PR further?
This commit is contained in:
commit
0ad71a07e8
@ -27,7 +27,12 @@ class File extends Constraint
|
||||
public $maxSizeMessage = 'The file is too large ({{ size }}). Allowed maximum size is {{ limit }}';
|
||||
public $mimeTypesMessage = 'The mime type of the file is invalid ({{ type }}). Allowed mime types are {{ types }}';
|
||||
|
||||
public $uploadIniSizeErrorMessage = 'The file is too large. Allowed maximum size is {{ limit }}';
|
||||
public $uploadFormSizeErrorMessage = 'The file is too large';
|
||||
public $uploadErrorMessage = 'The file could not be uploaded';
|
||||
public $uploadIniSizeErrorMessage = 'The file is too large. Allowed maximum size is {{ limit }}';
|
||||
public $uploadFormSizeErrorMessage = 'The file is too large';
|
||||
public $uploadPartialErrorMessage = 'The file was only partially uploaded';
|
||||
public $uploadNoFileErrorMessage = 'No file was uploaded';
|
||||
public $uploadNoTmpDirErrorMessage = 'No temporary folder was configured in php.ini';
|
||||
public $uploadCantWriteErrorMessage = 'Cannot write temporary file to disk';
|
||||
public $uploadExtensionErrorMessage = 'A PHP extension caused the upload to fail';
|
||||
public $uploadErrorMessage = 'The file could not be uploaded';
|
||||
}
|
||||
|
@ -50,6 +50,26 @@ class FileValidator extends ConstraintValidator
|
||||
case UPLOAD_ERR_FORM_SIZE:
|
||||
$this->context->addViolation($constraint->uploadFormSizeErrorMessage);
|
||||
|
||||
return false;
|
||||
case UPLOAD_ERR_PARTIAL:
|
||||
$this->context->addViolation($constraint->uploadPartialErrorMessage);
|
||||
|
||||
return false;
|
||||
case UPLOAD_ERR_NO_FILE:
|
||||
$this->context->addViolation($constraint->uploadNoFileErrorMessage);
|
||||
|
||||
return false;
|
||||
case UPLOAD_ERR_NO_TMP_DIR:
|
||||
$this->context->addViolation($constraint->uploadNoTmpDirErrorMessage);
|
||||
|
||||
return false;
|
||||
case UPLOAD_ERR_CANT_WRITE:
|
||||
$this->context->addViolation($constraint->uploadCantWriteErrorMessage);
|
||||
|
||||
return false;
|
||||
case UPLOAD_ERR_EXTENSION:
|
||||
$this->context->addViolation($constraint->uploadExtensionErrorMessage);
|
||||
|
||||
return false;
|
||||
default:
|
||||
$this->context->addViolation($constraint->uploadErrorMessage);
|
||||
|
@ -303,9 +303,11 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
return array(
|
||||
array(UPLOAD_ERR_INI_SIZE, 'uploadIniSizeErrorMessage', array('{{ limit }}' => UploadedFile::getMaxFilesize() . ' bytes')),
|
||||
array(UPLOAD_ERR_FORM_SIZE, 'uploadFormSizeErrorMessage'),
|
||||
array(UPLOAD_ERR_PARTIAL, 'uploadErrorMessage'),
|
||||
array(UPLOAD_ERR_NO_TMP_DIR, 'uploadErrorMessage'),
|
||||
array(UPLOAD_ERR_EXTENSION, 'uploadErrorMessage'),
|
||||
array(UPLOAD_ERR_PARTIAL, 'uploadPartialErrorMessage'),
|
||||
array(UPLOAD_ERR_NO_FILE, 'uploadNoFileErrorMessage'),
|
||||
array(UPLOAD_ERR_NO_TMP_DIR, 'uploadNoTmpDirErrorMessage'),
|
||||
array(UPLOAD_ERR_CANT_WRITE, 'uploadCantWriteErrorMessage'),
|
||||
array(UPLOAD_ERR_EXTENSION, 'uploadExtensionErrorMessage'),
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user