feat(post-form): enable adding photos when editing an entry (M2/R9)
Re-enable the FilePond browse/drop affordance in edit mode. On submit, existing locals + new uploads ride the photo_order manifest and cache-on-save reconciles the folder (delete dropped, renumber survivors photo-1..N, first = cover), so an entry's photos can now be added, removed and reordered from the front-end edit form. Verified end-to-end: add, remove, reorder, and all three in one save, plus create-with-photos and edit remove/reorder regressions. Depends on a local fix to add-page-by-form (its Grav-2.0 edit-mode header cast fatals on a new upload); that plugin is git-ignored, so the fix ships as a tracked patch in the superproject (deploy/patches/) rather than here. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -778,19 +778,17 @@ function editWaitForPond(cb, tries) {
|
||||
if (tries < 120) setTimeout(function () { editWaitForPond(cb, tries + 1); }, 50);
|
||||
}
|
||||
|
||||
// U7: load the entry's current photos into FilePond as LOCAL items. Local files
|
||||
// already live on the server, so FilePond shows them for reorder/removal but does
|
||||
// NOT re-upload them on save. Their filenames sort to folder order (first = cover)
|
||||
// and ride the `photo_order` manifest on submit; cache-on-save reconciles the
|
||||
// folder to match (U8). A broken media URL is skipped, never aborting the rest.
|
||||
// U7/R9: load the entry's current photos into FilePond as LOCAL items (already on
|
||||
// the server — shown for reorder/removal, never re-uploaded). Adding new photos on
|
||||
// edit is enabled (allowBrowse/allowDrop): on submit, existing filenames + any new
|
||||
// uploads ride the `photo_order` manifest and cache-on-save reconciles the folder
|
||||
// (delete dropped, renumber survivors photo-1..N, first = cover). A broken media
|
||||
// URL is skipped, never aborting the rest.
|
||||
//
|
||||
// Adding NEW photos on edit (R9) is intentionally suppressed here (allowBrowse /
|
||||
// allowDrop off) — a new upload on the edit save goes through add-page-by-form's
|
||||
// edit-mode file merge, which fatals on Grav 2.0 (`(array)$page->header()` yields
|
||||
// mangled protected-property keys, so `$original_frontmatter['photos']` is never
|
||||
// set → array_merge(null,…) TypeError). That's a stock, GPM-managed plugin we
|
||||
// must not fork, so add-photo-on-edit is deferred to the form-to-page/image-upload
|
||||
// rework. Remove + reorder (which never upload) work and are what M2 ships.
|
||||
// Add-on-edit depends on a local patch to add-page-by-form (stock GPM plugin's
|
||||
// edit-mode file merge fatals on Grav 2.0's Header object — see the patch note in
|
||||
// add-page-by-form.php). That patch is git-ignored, so it must be re-applied on a
|
||||
// fresh plugin install until upstream is forked.
|
||||
function editLoadPhotos(route) {
|
||||
fetch('/api/v1/pages' + route + '/media', { credentials: 'include', headers: { Accept: 'application/json' } })
|
||||
.then(function (r) { return r.ok ? r.json() : { data: [] }; })
|
||||
@@ -802,8 +800,7 @@ function editLoadPhotos(route) {
|
||||
return a.filename < b.filename ? -1 : (a.filename > b.filename ? 1 : 0);
|
||||
});
|
||||
editWaitForPond(function (pond) {
|
||||
// Keep remove + reorder; drop the add affordance (see note above).
|
||||
try { pond.setOptions({ allowBrowse: false, allowDrop: false, allowReorder: true }); } catch (e) { /* older API */ }
|
||||
try { pond.setOptions({ allowBrowse: true, allowDrop: true, allowReorder: true }); } catch (e) { /* older API */ }
|
||||
images.forEach(function (m) {
|
||||
try {
|
||||
var p = pond.addFile(route + '/' + m.filename, { type: 'local' });
|
||||
|
||||
Reference in New Issue
Block a user