public function parse($template = null)
{
// name is required
if ($this->attributes['name'] == '') {
throw new \SpoonFormException('A name is required for a file field. Please provide a name.');
}
// start html generation
$output = '<input type="file"';
// add attributes
$output .= $this->getAttributesHTML(array('[id]' => $this->attributes['id'], '[name]' => $this->attributes['name'])) . ' />';
// add help txt if needed
if (!$this->hideHelpTxt) {
if (isset($this->attributes['extension'])) {
$output .= '<p class="help-block">' . sprintf(BackendLanguage::getMessage('HelpFileFieldWithMaxFileSize', 'core'), $this->attributes['extension'], Form::getUploadMaxFileSize()) . '</p>';
} else {
$output .= '<p class="help-block">' . sprintf(BackendLanguage::getMessage('HelpMaxFileSize'), Form::getUploadMaxFileSize()) . '</p>';
}
}
// parse to template
if ($template !== null) {
$template->assign('file' . SpoonFilter::toCamelCase($this->attributes['name']), $output);
$template->assign('file' . SpoonFilter::toCamelCase($this->attributes['name']) . 'Error', $this->errors != '' ? '<span class="formError text-danger">' . $this->errors . '</span>' : '');
}
return $output;
}