has anyone experience with the Neos.Form.Builder? Because I want to send more then 1 Attachment with 1 file upload.
I tried it with multiple="multiple" in the Neos.Form FileUpload.html, but it only send the last Attachment.
I’m afraid that won’t be as simple as that. The example FileUpload Form Element is built to convert a single persistent resource.
You probably have to implement a custom Form Element class (along the lines of https://github.com/neos/form/blob/master/Classes/FormElements/FileUpload.php) and invoke the conversion manually in onSubmit() and/or create a custom type converter.
We are using this in the form builder and thus also need to pass all attachments in the email finisher. For this to work, we had to extend a method in that class a bit:
protected function addAttachments(SwiftMailerMessage $mail)
{
$formValues = $this->finisherContext->getFormValues();
if ($this->parseOption('attachAllPersistentResources')) {
foreach ($formValues as $formValue) {
if (is_array($formValue)) {
foreach ($formValue as $value) {
if ($value instanceof PersistentResource) {
$this->addAttachmentToMail($mail, $value);
}
}
} elseif ($formValue instanceof PersistentResource) {
$this->addAttachmentToMail($mail, $formValue);
} elseif ($formValue instanceof Image) {
$resource = $formValue->getResource();
$this->addAttachmentToMail($mail, $resource);
}
}
}
$attachmentConfigurations = $this->parseOption('attachments');
if (is_array($attachmentConfigurations)) {
foreach ($attachmentConfigurations as $attachmentConfiguration) {
if (isset($attachmentConfiguration['resource'])) {
$mail->attach(\Swift_Attachment::fromPath($attachmentConfiguration['resource']));
continue;
}
if (!isset($attachmentConfiguration['formElement'])) {
throw new FinisherException('The "attachments" options need to specify a "resource" path or a "formElement" containing the resource to attach', 1503396636);
}
$resource = ObjectAccess::getPropertyPath($formValues, $attachmentConfiguration['formElement']);
if (!$resource instanceof PersistentResource) {
continue;
}
$mail->attach(\Swift_Attachment::newInstance(stream_get_contents($resource->getStream()), $resource->getFilename(), $resource->getMediaType()));
}
}
}
protected function addAttachmentToMail(SwiftMailerMessage $mail, PersistentResource $resource)
{
$mail->attach(\Swift_Attachment::newInstance(stream_get_contents($resource->getStream()), $resource->getFilename(), $resource->getMediaType()));
}
We also allowed files from the image upload to get attached to the email.