Problem/Motivation
For my project, I need the ability to upload a file in a repeatable custom composite.
The composite consists of two fields, a single taxonomy term reference and a single file upload.
The only feature that is needed for the file upload is the ability to limit/define allowed file types.
Webform composite elements do not support managed file uploads.
Proposed resolution
The managed file element requires custom save, update, and delete callbacks which are used to rename, track, and managed upload files.
Rework the ManagedFile element to provide callbacks that can be re-used by Webform composite elements
Remaining tasks
- Allow managed files to be used with composite elements.
- Setup test composite managed file upload form with single and multiple examples.
- Determine where a composite element can save and delete managed files.
- Update WebformManagedFileBase::postSave and add ::syncFiles() and ::updateFiles() helper methods.
- Add file upload to webform_example_composite.module.
- Write tests.
- Write a change record.
User interface changes
Add ManagedFile elements to support composite element drop down.
API changes
- ::postSave and ::postDelete methods need to be added to the WebformCompositeElement plugin.
- WebformManagedFileBase::deleteFiles will need to be public and maybe static
Data model changes
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | 3007890-14.patch | 48.31 KB | jrockowitz |
| #11 | 3007890-11.patch | 48.2 KB | jrockowitz |
| #4 | 3007890-4.patch | 1.04 KB | jrockowitz |
| #3 | webform_documents_composite.zip | 8.58 KB | brado |
Comments
Comment #2
jrockowitz commentedIf all you immediately need is to limit the file upload types. I think you are missing a simple property. Can you please post your custom composite code in a zipped module?
Comment #3
brado commentedHere's what I have so far.
The file upload field loads but it doesn't work. I was saying the only feature I need from he field (other than uploading the file) is the ability to limit file types. I assumed it was the attribute that I was setting but wanted to make sure all the details were in there.
Comment #4
jrockowitz commented@brado You need to use
'#type': managed_fileinstead of'#type': file.The attached patch removes the exception which disables support for composite elements with a managed file upload element.
Your custom composite element starts to work but upload file is not being properly saved (ie it is still a temp file)
We need to rework the \Drupal\webform\Plugin\WebformElement\WebformManagedFileBase and the below methods would need to be refactored.
\Drupal\webform\Plugin\WebformElement\WebformManagedFileBase::postSave
\Drupal\webform\Plugin\WebformElement\WebformManagedFileBase::postDelete
\Drupal\webform\Plugin\WebformElement\WebformManagedFileBase::getFileDestinationUri
\Drupal\webform\Plugin\WebformElement\WebformManagedFileBase::getTestValues
The goal would be to get managed file uploads working for custom composites via the UI and code.
There is decent test coverage for the existing managed file element but we would need to write some more tests to prevent any regressions.
I can fully scope out this work over the weekend.
Comment #5
brado commented@jrock Awesome. You are a life saver!
Comment #6
jrockowitz commentedComment #7
jrockowitz commentedComment #11
jrockowitz commentedPlease review the attached patch. Make sure the change 'file' to 'managed_file' in your custom composite.
Comment #14
jrockowitz commentedComment #15
brado commentedWorks perfect!
Confirmed the file upload template side works like a charm and it shows up in the Webfrom REST GET response just like it needs to.
Comment #16
jrockowitz commentedHere is the change record.
Comment #18
jrockowitz commentedDone!