Skip to content
Snippets Groups Projects
Commit 5e15a78d authored by Jared Hancock's avatar Jared Hancock
Browse files

variable: Add .files to the FileUploadField in templates

parent bd8eeb55
No related branches found
No related tags found
No related merge requests found
...@@ -2184,6 +2184,42 @@ class FileUploadField extends FormField { ...@@ -2184,6 +2184,42 @@ class FileUploadField extends FormField {
$this->attachments->deleteAll(); $this->attachments->deleteAll();
} }
} }
function asVar($value, $id=false) {
return new FileFieldAttachments($this->getFiles());
}
function asVarType() {
return 'FileFieldAttachments';
}
}
class FileFieldAttachments {
var $files;
function __construct($files) {
$this->files = $files;
}
function __toString() {
$files = array();
foreach ($this->files as $f) {
$files[] = $f->file->name;
}
return implode(', ', $files);
}
function getVar($tag) {
switch ($tag) {
case 'files':
throw new OOBContent(OOBContent::FILES, $this->files->all());
}
}
static function getVarScope() {
return array(
'files' => __('Attached files'),
);
}
} }
class InlineFormData extends ArrayObject { class InlineFormData extends ArrayObject {
......
...@@ -127,7 +127,7 @@ class VariableReplacer { ...@@ -127,7 +127,7 @@ class VariableReplacer {
$type = $content->getType(); $type = $content->getType();
$existing = @$this->extras[$type] ?: array(); $existing = @$this->extras[$type] ?: array();
$this->extras[$type] = array_merge($existing, $content->getContent()); $this->extras[$type] = array_merge($existing, $content->getContent());
return ''; return $content->asVar();
} }
if ($parts[0] && @isset($this->variables[$parts[0]])) { //root override if ($parts[0] && @isset($this->variables[$parts[0]])) { //root override
...@@ -321,18 +321,25 @@ class PlaceholderList ...@@ -321,18 +321,25 @@ class PlaceholderList
class OOBContent extends Exception { class OOBContent extends Exception {
var $type; var $type;
var $content; var $content;
var $text;
const FILES = 'files'; const FILES = 'files';
function __construct($type, $content) { function __construct($type, $content, $asVar='') {
$this->type = $type; $this->type = $type;
$this->content = $content; $this->content = $content;
$this->text = $asVar;
} }
function getType() { return $this->type; } function getType() { return $this->type; }
function getContent() { return $this->content; } function getContent() { return $this->content; }
function asVar() { return $this->text; }
} }
/**
* Simple wrapper to represent a rendered or partially rendered template
* with extra content such as attachments
*/
class TextWithExtras { class TextWithExtras {
var $text = ''; var $text = '';
var $extras; var $extras;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment