Files
intotheeast-com-content/pages/02.post/post-form.md
T
m038andClaude Opus 4.8 aa5d34717e 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
2026-07-04 23:31:25 +02:00

210 lines
6.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: 'New Entry'
template: post-form
access:
site.login: true
# Parent (write target) is injected server-side from site.active_trip by the
# cache-on-save plugin (onFormValidationProcessed) — no manual sync needed.
#
# overwrite_mode is toggled per submit by cache-on-save (KTD1, Alt B): edit when
# the hidden edit_path field is filled (write back in place), false when empty
# (create a fresh dated folder via slug_field). The static value here is the
# create-safe fallback for if cache-on-save doesn't run — add-page-by-form stays
# stock (no fork), so a static `edit` would break create (empty edit_path -> '.').
pageconfig:
slug_field: 'date,title'
overwrite_mode: false
# published is NOT a static pagefrontmatter default anymore — it is an
# authoritative form field (below) so every submit (create AND edit) writes the
# owner's chosen publish state. Only `template` stays static here.
pagefrontmatter:
template: entry
form:
name: new-entry
action: /post
enctype: multipart/form-data
fields:
# Photos come first — they anchor what you'll write (Photos → Title →
# Content). After upload post-form.js auto-collapses this into a summary
# bar so the thumbnails don't crowd the writing area.
-
name: photos
label: Photos (16)
# Grav-managed filepond field. post-form.js hooks its beforeAddFile
# to convert HEIC->JPEG in the browser, then re-adds the JPEG via the
# public pond.addFile() API — FilePond keeps ownership of the upload
# and page-attach contract (U4).
type: filepond
multiple: true
destination: '@self'
# Max 6 photos per entry; at least 1 is required (enforced
# client-side in post-form.js initValidation).
limit: 6
accept:
- 'image/*'
-
name: title
label: Title
type: text
validate:
required: true
-
name: date
label: Date & Time
# Rendered as a native <input type="datetime-local"> by the theme
# override at templates/forms/fields/datetime/datetime.html.twig.
# No `default: now` — the stock text fallback would print the literal
# string "now" into the picker; post-form.js prefills the current
# local time instead (and the client validator requires this field).
type: datetime
format: 'Y-m-d H:i'
validate:
required: true
-
name: content
label: "What happened today?"
type: textarea
rows: 10
validate:
required: true
-
name: lat
label: Latitude
type: text
placeholder: 'tap "Get Location" below'
-
name: lng
label: Longitude
type: text
placeholder: ''
-
name: location_city
label: City
type: text
placeholder: 'e.g. Kyoto'
-
name: location_country
label: Country
type: text
placeholder: 'e.g. Japan'
-
name: weather_desc
label: Weather Condition
type: select
default: ''
options:
'': '— none —'
'Sunny': '☀️ Sunny'
'Partly cloudy': '⛅ Partly cloudy'
'Cloudy': '☁️ Cloudy'
'Foggy': '🌫️ Foggy'
'Drizzle': '🌦️ Drizzle'
'Rain': '🌧️ Rain'
'Snow': '❄️ Snow'
'Thunderstorm': '⛈️ Thunderstorm'
-
name: weather_temp_c
label: 'Temperature (°C)'
type: number
placeholder: 'tap "Get Weather" or type it'
validate:
min: -60
max: 60
-
name: transport_mode
label: 'How I got here'
type: select
default: ''
options:
'': '— not specified —'
'walking': '🚶 Walking'
'bicycle': '🚲 Bicycle'
'bus': '🚌 Bus'
'train': '🚆 Train'
'car': '🚗 Car'
'plane': '✈️ Plane'
# Hidden edit target. Empty on create (add-page-by-form falls through to
# slug_field and writes a fresh dated folder); on edit, post-form.js sets
# it to the entry's path so overwrite_mode:edit writes back in place.
-
name: edit_path
type: hidden
default: ''
# Advanced fields — collapsed behind "More options" (see U5).
# No hero_image field: journal entries render their hero from the first
# uploaded photo (entry-journal.html.twig uses entry.media.images|first),
# so an explicit hero filename was redundant. Stories still use hero_image
# but they aren't posted through this form.
-
name: published
label: Published
# Authoritative publish state (replaces the removed static
# pagefrontmatter.published). Default ON so new entries publish; the
# owner flips it OFF to save/keep a draft, or to unpublish on edit.
# validate.type:bool keeps it a real boolean in frontmatter (not '0').
type: toggle
classes: advanced-field
highlight: 1
default: 1
options:
1: 'Yes'
0: 'No'
validate:
type: bool
-
name: force_connect
label: Force connector line
type: toggle
classes: advanced-field
highlight: 0
default: 0
options:
1: 'Yes'
0: 'No'
validate:
type: bool
-
name: featured
label: Featured highlight
type: toggle
classes: advanced-field
highlight: 0
default: 0
options:
1: 'Yes'
0: 'No'
validate:
type: bool
novalidate: true
buttons:
-
type: submit
value: Post Daily
classes: btn-post
process:
add_page: true
upload: true
message: 'Entry posted successfully!'
reset: true
---