From 157bfc6b3a6951e18ace24e88100b902ede166cf Mon Sep 17 00:00:00 2001 From: Philipp Kitzberger Date: Fri, 17 May 2024 17:37:09 +0200 Subject: [PATCH] FIX: template for file field (again) File upload fields names and their representation in __trustedProperties need to follow certain rules: * name attribute needs to be an array, e.g. `yourfile[]` * in __trustedProperties it needs to be this: `"yourfile":{"name":[1],"type":[1],"tmp_name":[1],"error":[1],"size":[1]}` Multi-upload fields seem to be not possible at the moment. --- .../Form/MultiUploadViewHelper.php | 51 ------------------- .../Private/Partials/Form/Field/File.html | 12 +++-- 2 files changed, 7 insertions(+), 56 deletions(-) delete mode 100644 Classes/ViewHelpers/Form/MultiUploadViewHelper.php diff --git a/Classes/ViewHelpers/Form/MultiUploadViewHelper.php b/Classes/ViewHelpers/Form/MultiUploadViewHelper.php deleted file mode 100644 index ba91d88..0000000 --- a/Classes/ViewHelpers/Form/MultiUploadViewHelper.php +++ /dev/null @@ -1,51 +0,0 @@ -getName(); - $allowedFields = ['name', 'type', 'tmp_name', 'error', 'size']; - foreach ($allowedFields as $fieldName) { - $this->registerFieldNameForFormTokenGeneration($name . '[' . $fieldName . '][]'); - } - $this->tag->addAttribute('type', 'file'); - - if (isset($this->arguments['multiple'])) { - $this->tag->addAttribute('name', $name . '[]'); - } else { - $this->tag->addAttribute('name', $name); - } - - $this->setErrorClassAttribute(); - return $this->renderInput(); - } - - /** - * Renders and returns the tag - * - * @return string - * @api - */ - public function renderInput(): string - { - $data = []; - if (empty($this->tagName)) { - return ''; - } - foreach ($this->tag->getAttributes() as $attributeName => $attributeValue) { - $data[$attributeName] = $attributeValue; - } - $data['name'] = $this->tag->getTagName(); - if ($this->tag->hasContent()) { - $data['content'] = $this->tag->getContent(); - } - return json_encode($data); - } -} diff --git a/Resources/Private/Partials/Form/Field/File.html b/Resources/Private/Partials/Form/Field/File.html index bf71254..4b77c29 100644 --- a/Resources/Private/Partials/Form/Field/File.html +++ b/Resources/Private/Partials/Form/Field/File.html @@ -1,6 +1,9 @@ {namespace vh=In2code\Powermail\ViewHelpers} - + Inspired by EXT:powermail's MultiUploadViewHelper + + + + }" />