Files
intotheeast-com/deploy/patches/add-page-by-form-grav2-header.patch
T
m038andClaude Opus 4.8 1cf2d12bc7 fix(add-page-by-form): patch Grav-2.0 edit-mode header fatal + deploy wiring
Adding a new photo while editing an entry 500s: add-page-by-form's edit branch
reads existing frontmatter via `(array)$page->header()`, but Grav 2.0's
Grav\Common\Page\Header keeps data in a protected `items`, so the cast mangles
keys and `$original_frontmatter['photos']` is never set → array_merge(null,…)
TypeError. Fix: use Header::toArray() (clean keys, stdClass fallback) + guard the
per-field merge. Grav 2.0.7 does not change this — only the plugin fix does.

add-page-by-form is abandoned upstream (last release 2023-09) and its dir is
git-ignored/GPM-managed, so the fix is tracked as deploy/patches/*.patch and
re-applied after any GPM install/update:
- make apply-plugin-patches (local) — chained into install-plugins
- make remote-apply-plugin-patches-{test,prod} — piped over SSH into
  `patch -p1 --forward`; chained into remote-install-plugins / remote-update-plugins
Content syncs don't touch user/plugins/, so the patch survives them; only a GPM
op wipes it (now auto-restored). Runbook + README document the step and a
verify check. Remove once the plugin is forked.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-05 13:43:12 +02:00

39 lines
2.8 KiB
Diff

--- a/b/user/plugins/add-page-by-form/add-page-by-form.php 2026-07-05 12:03:55.849015242 +0200
+++ b/user/plugins/add-page-by-form/add-page-by-form.php 2026-07-05 11:55:06.175609339 +0200
@@ -619,7 +619,19 @@
if ($overwrite_mode !== 'false') {
if (file_exists($new_page_folder)) {
if ($overwrite_mode === 'edit') {
- $original_frontmatter = (array)$pages->get($new_page_folder)->header();
+ // intotheeast patch (temporary, pending upstream fork):
+ // On Grav 2.0 header() returns a Grav\Common\Page\Header
+ // object whose data sits in a PROTECTED `items` property,
+ // so the original `(array)$header` yields mangled keys
+ // (\0*\0items) and every frontmatter lookup below misses —
+ // `array_merge($original_frontmatter['photos'], …)` then
+ // fatals under PHP 8. Use toArray() (clean keys) when the
+ // Header exposes it; fall back to the cast for a plain
+ // stdClass (classic pages).
+ $__header = $pages->get($new_page_folder)->header();
+ $original_frontmatter = (is_object($__header) && method_exists($__header, 'toArray'))
+ ? $__header->toArray()
+ : (array)$__header;
} else {
Folder::delete($new_page_folder);
}
@@ -708,7 +720,13 @@
$file_fields_updated = array();
foreach ($file_fields as $file_field => $uploads) {
- $file_fields_updated[$file_field] = array_merge($original_frontmatter[$file_field], $uploads);
+ // intotheeast patch: entries that render from folder-scanned
+ // media carry no matching frontmatter key, so fall back to []
+ // rather than fatal array_merge() on a missing/null original.
+ $existing = (isset($original_frontmatter[$file_field]) && is_array($original_frontmatter[$file_field]))
+ ? $original_frontmatter[$file_field]
+ : array();
+ $file_fields_updated[$file_field] = array_merge($existing, $uploads);
// Get any (uploaded and then) deleted files
foreach ($copy_files['deleted'] as $file_to_delete) {