sitegeist/fusionform-upload

There is no license information available for the latest version (v1.0.1) of this package.

v1.0.1 2023-05-01 07:22 UTC

This package is auto-updated.

Last update: 2024-11-30 02:44:23 UTC


README

Alternate implementations of Neos.Fusion.Forms:Upload

The package implements file uploads for Fusion.Forms with the main deviation that uploaded files are persisted in a cache and not as persistent resources. This has the advantage that resources do not have to manually cleaned and are deleted after the configured cache period automatically.

To achieve this the package adds the classes \Sitegeist\FusionForm\Upload\Domain\CachedUploadedFile which is a version of the psr-uploaded file that has an additional cache-identifier. For uploading multiple files the collection \Sitegeist\FusionForm\Upload\Domain\CachedUploadedFileCollection is added aswell. For both classed type converters are provided that ensure that values are cached and previously submitted values are restored for processing.

!!! This package does not support the RuntimeForm MultiStepProcess yet, this may be added in future versions !!!

Authors & Sponsors

The development and the public-releases of this package is generously sponsored by our employer http://www.sitegeist.de.

Fusion prototype - Sitegeist.FusionForm.Upload:Field.Upload

Single file upload

The prototype Sitegeist.FusionForm.Upload:Field.Upload allows to render a single file field. It will usually be rendered in a field-container together with a rendering of previously uploaded files. The submitted value should be interpreted as \Sitegeist\FusionForm\Upload\Domain\CachedUploadedFile by the receiving controller or the runtime form schema.

<Neos.Fusion.Form:FieldContainer label="File" field.name="file">

    <!-- show imformations about previously uploaded files -->
    <Neos.Fusion:Fragment @if.has={Type.instance(field.getCurrentValue(), 'Sitegeist\FusionForm\Upload\Domain\CachedUploadedFile')}>
        {field.getCurrentValue().clientFilename} ({field.getCurrentValue().clientMediaType}/{field.getCurrentValue().size})
    </Neos.Fusion:Fragment>

    <!-- the form field -->
    <Sitegeist.FusionForm.Upload:Field.Upload />

</Neos.Fusion.Form:FieldContainer>

The according schema runtime forms will likely look like this.

file = ${Form.Schema.forType('Sitegeist\\FusionForm\\Upload\\Domain\\CachedUploadedFile')}
requiredFile = ${Form.Schema.forType('Sitegeist\\FusionForm\\Upload\\Domain\\CachedUploadedFile').required}
jpgFile = ${Form.Schema.forType('Sitegeist\\FusionForm\\Upload\\Domain\\CachedUploadedFile').validator('Sitegeist.FusionForm.Upload:UploadedFile', {'allowedExtensions': ["jpg"]})}

Multio file upload

For multiple uploads the prototype Sitegeist.FusionForm.Upload:Field.Upload supports the field.multiple property. It will usually be rendered in a field-container together with a rendering of previously uploaded files. The submitted value should be interpreted as \Sitegeist\FusionForm\Upload\Domain\CachedUploadedFileCollection by the receiving controller or the runtime form schema.

<Neos.Fusion.Form:FieldContainer label="Files" field.name="files" field.multiple={true}>

    <!-- show imformations about previously uploaded files since we  have a multifield we habe to loop here-->
    <Neos.Fusion:Loop items={field.getCurrentValue()} itemName="item" @if={field.getCurrentValue()}>
        <Neos.Fusion:Fragment @if.has={Type.instance(item, 'Sitegeist\FusionForm\Upload\Domain\CachedUploadedFile')}>
            {item.clientFilename} ({item.clientMediaType} / {item.size}) <br/>
        </Neos.Fusion:Fragment>
    </Neos.Fusion:Loop>
  
    <!-- render input field -->
    <Sitegeist.FusionForm.Upload:Field.Upload />
    
</Neos.Fusion.Form:FieldContainer>

The according schema runtime forms will likely look like this.

file = ${Form.Schema.forType('Sitegeist\\FusionForm\\Upload\\Domain\\CachedUploadedFileCollection')}
requiredFile = ${Form.Schema.forType('Sitegeist\\FusionForm\\Upload\\Domain\\CachedUploadedFileCollection').required}
jpgFile = ${Form.Schema.forType('Sitegeist\\FusionForm\\Upload\\Domain\\CachedUploadedFileCollection').validator('Sitegeist.FusionForm.Upload:UploadedFileCollection', {'allowedExtensions': ["jpg"]})}

Attaching uploaded files in emails

Since the files implement the interface \Psr\Http\Message\UploadedFileInterface the existing Email Action can already handle those types.

email {
    type = 'Neos.Fusion.Form.Runtime:Email'
    options {
        attachments = Neos.Fusion:DataStructure {
          file = ${data.file} 
        }
    }
}

CachedUploadedFileCollection can be assigned directly to the mail attachments.

email {
    type = 'Neos.Fusion.Form.Runtime:Email'
    options {
        attachments = ${data.files.asArray}
    }
}

UploadedFile caching

The uploaded files are persisted in the Sitegeist_FusionForm_Upload_UploadedFileCache which allows to configure altenate cache backends and the cache lifetime.

Sitegeist_FusionForm_Upload_UploadedFileCache:
  frontend: Neos\Cache\Frontend\VariableFrontend
  backend: Neos\Cache\Backend\FileBackend
  backendOptions:
    defaultLifetime: 3600
./flow flow:cache:flushone Sitegeist_FusionForm_Upload_UploadedFileCache

Installation

Sitegeist.Taxonomy is available via packagist run composer require sitegeist/fusionform-upload to install.

We use semantic-versioning so every breaking change will increase the major-version number.

Contribution

We will gladly accept contributions. Please send us pull requests.

License

See LICENSE