public function Field($properties = array()) { // Calculated config as per jquery.fileupload-ui.js $allowedMaxFileNumber = $this->getAllowedMaxFileNumber(); $config = array('url' => $this->Link('upload'), 'urlSelectDialog' => $this->Link('select'), 'urlAttach' => $this->Link('attach'), 'urlFileExists' => $this->Link('fileexists'), 'acceptFileTypes' => '.+$', 'maxNumberOfFiles' => $allowedMaxFileNumber ? $allowedMaxFileNumber - count($this->getItemIDs()) : null, 'replaceFile' => $this->getUpload()->getReplaceFile()); // Validation: File extensions if ($allowedExtensions = $this->getAllowedExtensions()) { $config['acceptFileTypes'] = '(\\.|\\/)(' . implode('|', $allowedExtensions) . ')$'; $config['errorMessages']['acceptFileTypes'] = _t('File.INVALIDEXTENSIONSHORT', 'Extension is not allowed'); } // Validation: File size if ($allowedMaxFileSize = $this->getValidator()->getAllowedMaxFileSize()) { $config['maxFileSize'] = $allowedMaxFileSize; $config['errorMessages']['maxFileSize'] = _t('File.TOOLARGESHORT', 'File size exceeds {size}', array('size' => File::format_size($config['maxFileSize']))); } // Validation: Number of files if ($allowedMaxFileNumber) { if ($allowedMaxFileNumber > 1) { $config['errorMessages']['maxNumberOfFiles'] = _t('UploadField.MAXNUMBEROFFILESSHORT', 'Can only upload {count} files', array('count' => $allowedMaxFileNumber)); } else { $config['errorMessages']['maxNumberOfFiles'] = _t('UploadField.MAXNUMBEROFFILESONE', 'Can only upload one file'); } } // add overwrite warning error message to the config object sent to Javascript if ($this->getOverwriteWarning()) { $config['errorMessages']['overwriteWarning'] = _t('UploadField.OVERWRITEWARNING', 'File with the same name already exists'); } $mergedConfig = array_merge($config, $this->ufConfig); return parent::Field(array('configString' => Convert::raw2json($mergedConfig), 'config' => new ArrayData($mergedConfig), 'multiple' => $allowedMaxFileNumber !== 1)); }