Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm, that this change fixes #32

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Error\Error;
use TYPO3\CMS\Form\Security\HashScope;
use TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface;
use TYPO3\CMS\Form\Mvc\Property\Exception\TypeConverterException;
use TYPO3\CMS\Form\Mvc\Property\TypeConverter\PseudoFileReference;
Expand Down Expand Up @@ -70,7 +71,7 @@ protected function convertFromPointerToResource($source, $targetType, array $con
try {
// File references use numeric resource pointers, direct
// file relations are using "file:" prefix (e.g. "file:5")
$resourcePointer = $this->hashService->validateAndStripHmac($resourcePointerSource);
$resourcePointer = $this->hashService->validateAndStripHmac($resourcePointerSource,HashScope::ResourcePointer->prefix());
if (strpos($resourcePointer, 'file:') === 0) {
$fileUid = (int)substr($resourcePointer, 5);
$resource = $this->createFileReferenceFromFalFileObject($this->resourceFactory->getFileObject($fileUid));
Expand Down
10 changes: 10 additions & 0 deletions Classes/ViewHelpers/Form/UploadedResourceViewHelper.php

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, what this change fixes? Is it also related to #32?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly I discovered some problems with the Upload field not resolving/showing the previous uploaded file when the same form step is shown again. It was with the multiple option disabled.
These changes should handle single or multiupload the same way
I was testing a multistep form at that time.

Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,20 @@ public function render(): string
$this->tag->addAttribute('type', 'file');

if (isset($this->arguments['multiple'])) {
$multiple = true;
$this->tag->addAttribute('name', $name . '[]');
} else {
$this->tag->addAttribute('name', $name);
$multiple = false;
}

$this->setErrorClassAttribute();
$output .= $this->tag->render();

if ($resources !== null) {
if ($resources instanceof FileReference) {
$resources = [$resources];
}
foreach ($resources as $key => $resource) {
$resourcePointerIdAttribute = '';
if ($this->hasArgument('id')) {
Expand All @@ -126,6 +131,9 @@ public function render(): string
}
$output .= '<input type="hidden" name="' . htmlspecialchars($this->getName()) . '[submittedFile][resourcePointer][]" value="' . htmlspecialchars($this->hashService->appendHmac((string)$resourcePointerValue, HashScope::ResourcePointer->prefix())) . '"' . $resourcePointerIdAttribute . ' />';
}
if ($multiple == false) {
$resources = reset($resources);
}
$this->templateVariableContainer->add($as, $resources);
$output .= $this->renderChildren();
$this->templateVariableContainer->remove($as);
Expand Down Expand Up @@ -157,6 +165,8 @@ protected function getUploadedResources()
$ex = $this->propertyMapper->convert($resource, FileReference::class);
$return = array_merge($return, $ex);
}
} elseif ($resources instanceof FileReference) {
return $resources;
}
return $return;
}
Expand Down