feat(post-form): U1 — shared create/edit form + published field + owner_username
One /post form now drives both create and edit (KTD1, Alt B): cache-on-save toggles add-page-by-form's overwrite_mode per submit — 'edit' when the new hidden edit_path field is filled (write back in place, stable URL), 'false' when empty (fresh dated folder via slug_field). add-page-by-form stays stock (no fork); the toggle lives in cache-on-save, which reads edit_path and mutates the /post page header's pageconfig before add-page-by-form's onFormProcessed runs. - post-form.md: overwrite_mode:false (create-safe fallback), hidden edit_path, authoritative published toggle (default on), removed the static pagefrontmatter.published so the field wins on every submit (KTD3). - cache-on-save.php: editPathFromForm + setOverwriteMode helpers. - site.yaml: owner_username (single source of truth for the KTD8 owner gate). Verified against the 2.0.4 container: create writes a fresh dated folder with published:true/false as a real boolean (V1, V2); edit writes in place with the slug/URL unchanged; save-as-draft-on-create works. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H1FrCYNq6RXdGYbn5PFrhM
This commit is contained in:
@@ -48,6 +48,46 @@ class CacheOnSavePlugin extends Plugin
|
||||
}
|
||||
|
||||
$form->setData('parent', $this->resolveDailiesParent($activeTrip));
|
||||
|
||||
// One shared /post form drives both create and edit (KTD1). add-page-by-form
|
||||
// reads overwrite_mode from the /post page header's pageconfig (not form
|
||||
// data), so we toggle it here per submit:
|
||||
// - edit (edit_path present) -> overwrite_mode:edit, writes back in place
|
||||
// - create (edit_path empty) -> overwrite_mode:false, so stock falls
|
||||
// through to slug_field (date,title) and writes a fresh dated folder.
|
||||
// This keeps add-page-by-form stock (no fork), since a static
|
||||
// overwrite_mode:edit would break create (empty edit_path slugs to '.').
|
||||
$editPath = $this->editPathFromForm($form);
|
||||
$this->setOverwriteMode($editPath === '' ? 'false' : 'edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* The hidden edit_path form field, trimmed. Empty string when creating a new
|
||||
* entry; the entry's `<route>/entry.md` path when editing (set by post-form.js).
|
||||
*/
|
||||
private function editPathFromForm($form): string
|
||||
{
|
||||
$value = $form->value('edit_path');
|
||||
return is_string($value) ? trim($value) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Override add-page-by-form's overwrite_mode by mutating the current (/post)
|
||||
* page header's pageconfig. add-page-by-form reads
|
||||
* `$grav['page']->header()->pageconfig['overwrite_mode']` (add-page-by-form.php
|
||||
* :385) from the same page singleton, and Page::header() returns a cached
|
||||
* instance, so this write is visible when its onFormProcessed runs afterwards.
|
||||
*/
|
||||
private function setOverwriteMode(string $mode): void
|
||||
{
|
||||
$page = $this->grav['page'] ?? null;
|
||||
if (!$page) {
|
||||
return;
|
||||
}
|
||||
$header = $page->header();
|
||||
$pageconfig = (isset($header->pageconfig) && is_array($header->pageconfig)) ? $header->pageconfig : [];
|
||||
$pageconfig['overwrite_mode'] = $mode;
|
||||
$header->pageconfig = $pageconfig;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user