use wcf\data\file\thumbnail\FileThumbnailList;
use wcf\system\file\processor\FileProcessor;
use wcf\system\file\processor\IFileProcessor;
+use wcf\system\form\builder\field\validation\FormFieldValidationError;
use wcf\system\form\builder\TObjectTypeFormNode;
use wcf\util\ArrayUtil;
use wcf\util\ImageUtil;
if ($file->fileID === $value) {
$this->files = [$file];
$fileIDs[] = $value;
+ } else {
+ $value = null;
}
} else {
if (!\is_array($value)) {
$fileList->readObjects();
$this->files = $fileList->getObjects();
- $fileIDs = $fileList->getObjectIDs();
+ // remove obsolete file IDs from $value
+ $fileIDs = $value = $fileList->getObjectIDs();
}
if ($fileIDs !== []) {
return parent::value($value);
}
+ #[\Override]
+ public function validate()
+ {
+ if ($this->isRequired() && $this->files === []) {
+ $this->addValidationError(new FormFieldValidationError('empty'));
+ }
+
+ $fileProcessor = $this->getFileProcessor();
+
+ if (\count($this->files) > $fileProcessor->getMaximumCount($this->context)) {
+ $this->addValidationError(
+ new FormFieldValidationError(
+ 'maximumFiles',
+ 'wcf.form.field.fileProcessor.error.maximumFiles',
+ [
+ 'maximumCount' => $fileProcessor->getMaximumCount($this->context),
+ 'count' => \count($this->files),
+ ]
+ )
+ );
+ }
+
+ parent::validate();
+ }
+
+
/**
* Returns the context for the file processor.
*/