Skip to content

[3.0] Open the calendar's event form on a date instead of refusing to open - #9573

Open
albertlast wants to merge 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/calendar-post-event-date
Open

[3.0] Open the calendar's event form on a date instead of refusing to open#9573
albertlast wants to merge 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/calendar-post-event-date

Conversation

@albertlast

Copy link
Copy Markdown
Collaborator

Description

Clicking Post Event in the calendar produces "Invalid date" and nothing else.

This happens on a default install. cal_allow_unlinked is empty until somebody turns
it on, and in that case Calendar::post() hands a new event to Post::call() instead of
to the standalone editor — so the ordinary out-of-the-box path is the broken one. With the
setting enabled the standalone editor opens fine, which is probably why this has gone
unnoticed.

There turned out to be two faults in that path, the second hidden behind the first.

1. The form refuses to open without a date.
Event::setRequestedStartAndDuration() ends by fatalling with invalid_date when it
cannot find a start date. That is correct for the five callers that use it while saving
an event. But Post::initiateEvent() calls it while opening the form, where no date has
been chosen yet.

Event(-1) already defaults its start to now for precisely this situation — its own case
label says "Preparing default data to show in the calendar posting form", and
Calendar::post() depends on it, constructing new Event(-1) with no properties at all.
So the method is now only asked for a start when something actually supplied one, and
otherwise the constructor's default applies, exactly as it does for the standalone editor.

2. The day you clicked was ignored.
The same method reads only $_POST, so the year, month and day that the calendar
puts into its day links never reached it. Those are now passed through, so a link carrying
a date opens the form on that date.

3. A second fatal underneath the first.
Once the form got far enough to build the event, title and location were being passed
as null whenever the request did not carry them — and both are typed string on Event,
so the assignment threw Cannot assign null to property SMF\Calendar\Event::$title. They
are omitted instead, which is what Event(-1) expects: both already default to ''.

How this was checked

On a default install, with cal_allow_unlinked left untouched:

  • the Post Event button opens the form, with Start and End set to today
  • a link carrying year=2027;month=3;day=14 opens the form on 2027-03-14 — previously
    that was ignored even when the fatal did not fire
  • submitting the form creates the event and its topic: both appear on the calendar and the
    board index

Then with cal_allow_unlinked enabled, to confirm the standalone editor still opens
normally. The error log was empty after all of it.

Not changed here

The calendar's own Post Event button builds its URL with no date at all
(Sources/Actions/Calendar.php:340), so it opens on today rather than on the month being
viewed. With this fix that is harmless, just not ideal; changing it is a separate decision
about what that button should mean.

Issues References (Fixes|Related|Closes)

Found while testing #7933; unrelated to that PR.

Clicking "Post Event" in the calendar produced "Invalid date" and nothing
else. It happened on a default install, because cal_allow_unlinked is empty
until somebody turns it on, and Calendar::post() then hands a new event to
Post::call() rather than to the standalone editor.

There were two faults in that path, the second hidden behind the first.

Event::setRequestedStartAndDuration() ends by fatalling with 'invalid_date'
when it cannot find a start date. That is right for the five places that call
it while saving, but initiateEvent() calls it while *opening the form*, where
no date has been chosen yet. Event(-1) already defaults its start to now for
exactly this case - it is what Calendar::post() relies on when it builds the
standalone editor with no properties at all - so the method is now only asked
for a start when something actually supplied one.

That method also reads only $_POST, so the year, month and day the calendar
puts in its day links never arrived and the form ignored the day that was
clicked. Those values are now passed through, and a date in the query string
opens the form on it.

With the fatal gone, a second one appeared underneath: title and location were
passed as null when the request did not carry them, and both are typed string
on Event, so assigning null threw. They are omitted instead, which is what
Event(-1) expects - both already default to an empty string.

Checked on a default install with the setting untouched: the button now opens
the form on today, a link carrying year=2027;month=3;day=14 opens it on that
date, and posting the form creates the event and its topic. Also checked with
cal_allow_unlinked enabled, so the standalone editor still works, and the
error log stayed empty throughout.

Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
@jdarwood007 jdarwood007 added this to the 3.0 Alpha 6 milestone Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants