+{assign var="files" value=$field->getFiles()}
{if $maxUploads === 1 && $imageOnly}
<div class="fileUpload__preview">
{if $field->getValue()}
- {*<woltlab-core-file>…</woltlab-core-file>*}
- <ul class="fileUpload__preview__buttons buttonList">
- <li>
- <button class="button small" type="button">
- {lang}wcf.global.button.delete{/lang}
- </button>
- </li>
- </ul>
+ {assign var="file" value=$files|reset}
+ {unsafe:$file->toHtmlElement()}
{/if}
</div>
{else}
namespace wcf\system\form\builder\field;
+use wcf\data\file\File;
+use wcf\data\file\FileList;
use wcf\system\file\processor\FileProcessor;
use wcf\system\file\processor\IFileProcessor;
use wcf\system\form\builder\TObjectTypeFormNode;
+use wcf\util\ArrayUtil;
use wcf\util\ImageUtil;
/**
private array $context = [];
+ /**
+ * @var File[]
+ */
+ private array $files = [];
+
#[\Override]
public function readValue()
{
- \wcfDebug($this->getDocument()->getRequestData());
if ($this->getDocument()->hasRequestData($this->getPrefixedId())) {
- $this->context = $this->getDocument()->getRequestData($this->getPrefixedId());
+ $value = $this->getDocument()->getRequestData($this->getPrefixedId());
+
+ if ($this->isSingleFileUpload()) {
+ $this->value(\intval($value));
+ } else {
+ $this->value(ArrayUtil::toIntegerArray($value));
+ }
}
+
+ return $this;
+ }
+
+ #[\Override]
+ public function hasSaveValue()
+ {
+ return $this->isSingleFileUpload();
}
#[\Override]
return $this->getObjectType()->getProcessor();
}
+ private function isSingleFileUpload(): bool
+ {
+ return $this->getFileProcessor()->getMaximumCount($this->context) === 1;
+ }
+
#[\Override]
public function getObjectTypeDefinition()
{
return 'com.woltlab.wcf.file';
}
+ public function getFiles(): array
+ {
+ return $this->files;
+ }
+
+ #[\Override]
+ public function value($value)
+ {
+ if ($this->isSingleFileUpload()) {
+ $file = new File($value);
+ if ($file->fileID === $value) {
+ $this->files = [$file];
+ }
+
+ return parent::value($value);
+ } else {
+ if (!\is_array($value)) {
+ $value = [$value];
+ }
+
+ $fileList = new FileList();
+ $fileList->setObjectIDs($value);
+ $fileList->readObjects();
+ $this->files = $fileList->getObjects();
+
+ return parent::value($value);
+ }
+ }
+
/**
* Returns the context for the file processor.
*/