-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add multiple option to FileUpload element
- Loading branch information
Showing
14 changed files
with
6,435 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Remind\Form\Domain\Finishers; | ||
|
||
use TYPO3\CMS\Core\Mail\FluidEmail; | ||
use TYPO3\CMS\Extbase\Domain\Model\FileReference; | ||
use TYPO3\CMS\Form\Domain\Finishers\EmailFinisher as BaseEmailFinisher; | ||
use TYPO3\CMS\Form\Domain\Model\FormElements\FileUpload; | ||
use TYPO3\CMS\Form\Domain\Runtime\FormRuntime; | ||
|
||
class EmailFinisher extends BaseEmailFinisher | ||
{ | ||
private bool $attachUploads = false; | ||
|
||
protected function executeInternal(): string|null | ||
{ | ||
// temporarily store attachUploads option to use in initializeFluidEmail | ||
$this->attachUploads = (bool) $this->parseOption('attachUploads'); | ||
|
||
// set option to false so BaseEmailFinisher skips attaching uploads | ||
$this->options['attachUploads'] = false; | ||
|
||
parent::executeInternal(); | ||
|
||
return null; | ||
} | ||
|
||
protected function initializeFluidEmail(FormRuntime $formRuntime): FluidEmail | ||
{ | ||
$mail = parent::initializeFluidEmail($formRuntime); | ||
|
||
if ($this->attachUploads) { | ||
foreach ($formRuntime->getFormDefinition()->getRenderablesRecursively() as $element) { | ||
if (!$element instanceof FileUpload) { | ||
continue; | ||
} | ||
$files = $formRuntime[$element->getIdentifier()]; | ||
if ($files) { | ||
// $files may contain single file or multiple files | ||
if (!is_array($files)) { | ||
$files = [$files]; | ||
} | ||
|
||
foreach ($files as $file) { | ||
if ($file instanceof FileReference) { | ||
$file = $file->getOriginalResource(); | ||
} | ||
$mail->attach($file->getContents(), $file->getName(), $file->getMimeType()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return $mail; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Remind\Form\Mvc\Property; | ||
|
||
use Remind\Form\Mvc\Property\TypeConverter\MultiUploadedFileReferenceConverter; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Form\Domain\Model\FormElements\FileUpload; | ||
use TYPO3\CMS\Form\Domain\Model\Renderable\RenderableInterface; | ||
|
||
class PropertyMappingConfiguration | ||
{ | ||
public function afterBuildingFinished(RenderableInterface $renderable): void | ||
{ | ||
if ( | ||
$renderable instanceof FileUpload && | ||
!empty($renderable->getProperties()['multiple']) | ||
) { | ||
$typeConverter = GeneralUtility::makeInstance(MultiUploadedFileReferenceConverter::class); | ||
$renderable | ||
->getRootForm() | ||
->getProcessingRule($renderable->getIdentifier()) | ||
->getPropertyMappingConfiguration() | ||
->setTypeConverter($typeConverter); | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
Classes/Mvc/Property/TypeConverter/MultiUploadedFileReferenceConverter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Remind\Form\Mvc\Property\TypeConverter; | ||
|
||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Extbase\Error\Error; | ||
use TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface; | ||
use TYPO3\CMS\Extbase\Property\TypeConverter\AbstractTypeConverter; | ||
use TYPO3\CMS\Form\Mvc\Property\TypeConverter\UploadedFileReferenceConverter; | ||
|
||
class MultiUploadedFileReferenceConverter extends AbstractTypeConverter | ||
{ | ||
private UploadedFileReferenceConverter $uploadedFileReferenceConverter; | ||
|
||
public function __construct() | ||
{ | ||
$this->uploadedFileReferenceConverter = GeneralUtility::makeInstance(UploadedFileReferenceConverter::class); | ||
} | ||
|
||
/** | ||
* @param mixed[] $convertedChildProperties | ||
* @return \TYPO3\CMS\Extbase\Domain\Model\AbstractFileFolder[]|Error|null | ||
*/ | ||
public function convertFrom( | ||
mixed $source, | ||
mixed $targetType, | ||
array $convertedChildProperties = [], | ||
PropertyMappingConfigurationInterface $configuration = null | ||
): array|Error|null { | ||
if (is_array($source)) { | ||
$resources = []; | ||
foreach ($source as $file) { | ||
$resource = $this->uploadedFileReferenceConverter->convertFrom($file, $targetType, $convertedChildProperties, $configuration); | ||
|
||
if ($resource instanceof Error) { | ||
return $resource; | ||
} | ||
|
||
if ($resource) { | ||
$resources[] = $resource; | ||
} | ||
} | ||
return $resources; | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
plugin.tx_form { | ||
settings { | ||
yamlConfigurations { | ||
1731425366 = EXT:rmnd_form/Configuration/Yaml/FormSetup.yaml | ||
} | ||
} | ||
} | ||
|
||
module.tx_form { | ||
settings { | ||
yamlConfigurations { | ||
1731425366 = EXT:rmnd_form/Configuration/Yaml/FormSetup.yaml | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
prototypes: | ||
standard: | ||
finishersDefinition: | ||
EmailToReceiver: | ||
implementationClassName: Remind\Form\Domain\Finishers\EmailFinisher |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
prototypes: | ||
standard: | ||
finishersDefinition: | ||
EmailToSender: | ||
implementationClassName: Remind\Form\Domain\Finishers\EmailFinisher |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
prototypes: | ||
standard: | ||
formElementsDefinition: | ||
FileUpload: | ||
formEditor: | ||
editors: | ||
299: | ||
identifier: multiple | ||
templateName: Inspector-CheckboxEditor | ||
label: formEditor.elements.FileUpload.editor.multiple.label | ||
propertyPath: properties.multiple | ||
# Add Mime Types from ImageUpload Element | ||
300: | ||
selectOptions: | ||
80: | ||
value: image/jpeg | ||
label: formEditor.elements.ImageUpload.editor.allowedMimeTypes.jpg | ||
90: | ||
value: image/png | ||
label: formEditor.elements.ImageUpload.editor.allowedMimeTypes.png | ||
100: | ||
value: image/bmp | ||
label: formEditor.elements.ImageUpload.editor.allowedMimeTypes.bmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
prototypes: | ||
standard: | ||
formElementsDefinition: | ||
ImageUpload: null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
imports: | ||
- { resource: "./FormElements/FileUpload.yaml" } | ||
- { resource: "./FormElements/ImageUpload.yaml" } | ||
|
||
- { resource: "./Finishers/EmailToSender.yaml" } | ||
- { resource: "./Finishers/EmailToReceiver.yaml" } | ||
|
||
prototypes: | ||
standard: | ||
formEditor: | ||
translationFiles: | ||
1731478859: "EXT:rmnd_form/Resources/Private/Language/locallang.xlf" | ||
formEngine: | ||
translationFiles: | ||
1731478859: "EXT:rmnd_form/Resources/Private/Language/locallang.xlf" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8" standalone="yes" ?> | ||
<xliff version="1.0"> | ||
<file source-language="en" datatype="plaintext" original="EXT:rmnd_form/Resources/Private/Language/de.locallang.xlf" product-name="rmnd_form"> | ||
<header/> | ||
<body> | ||
<trans-unit id="formEditor.elements.FileUpload.editor.multiple.label"> | ||
<target>Mehrfach</target> | ||
</trans-unit> | ||
</body> | ||
</file> | ||
</xliff> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8" standalone="yes" ?> | ||
<xliff version="1.0"> | ||
<file source-language="en" datatype="plaintext" original="EXT:rmnd_form/Resources/Private/Language/locallang.xlf" product-name="rmnd_form"> | ||
<header/> | ||
<body> | ||
<trans-unit id="formEditor.elements.FileUpload.editor.multiple.label"> | ||
<source>Multiple</source> | ||
</trans-unit> | ||
</body> | ||
</file> | ||
</xliff> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.