Allow referencing existing assets (fixed Replicator Asset field issue) #41
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request allows for referencing existing assets in Guest Entries forms. This means you can retain the same image currently present when using file uploads in a Replicator field.
Hopefully fixes #38.
Example
If you have a Replicator field, with an asset inside it.
On creation of an entry, you can upload an entry just fine. However, when you go to update that asset, the selected asset is removed. This only applies for Replicator fields with file uploads in them.
To workaround the issue, on the edit form, when you're looping through Replicator iterations, you can use a hidden field which when submitted will tell Guest Entries to retain the currently selected file.
Why you need to do it this way just for Replicator fields
And now for the explanation as to why you need to do it this way & just for asset fields inside Replicator fields....
Essentially, whenever you update an entry, we merge in the data we've got from the request into the entry's existing data & hit save.
This means if you update an entry but haven't changed any 'root' asset fields (ones not inside Replicators/Bards/etc), we leave that alone and the data for it remains untouched.
If you upload a new file to replace it, then obviously we do overwrite the existing value but that's expected.
However, when it comes to updating stuff inside Replicator/Bard fields, stuff works slightly differently. If you provide any data for the replicator field at all, we'll replace the entire value of the Replicator value, not just the value for the part of the Replicator field you're editing.
We do this as we have no way to know if you've removed an item from the Replicator field. So when you update a Replicator field with no value for the Assets field, we set it to null and it's essentially being reset.
That's exactly what's happening in the issue I mentioned above.
The solution essentially means that we allow you to keep the existing value of the Assets field by providing the path of the asset(s) you wish to save to the field.
To Do