[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
Open
[3.0] Open the calendar's event form on a date instead of refusing to open#9573albertlast wants to merge 1 commit into
albertlast wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Clicking Post Event in the calendar produces "Invalid date" and nothing else.
This happens on a default install.
cal_allow_unlinkedis empty until somebody turnsit on, and in that case
Calendar::post()hands a new event toPost::call()instead ofto 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 withinvalid_datewhen itcannot 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 hasbeen chosen yet.
Event(-1)already defaults its start to now for precisely this situation — its own caselabel says "Preparing default data to show in the calendar posting form", and
Calendar::post()depends on it, constructingnew 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 theyear,monthanddaythat the calendarputs 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,
titleandlocationwere being passedas
nullwhenever the request did not carry them — and both are typedstringonEvent,so the assignment threw
Cannot assign null to property SMF\Calendar\Event::$title. Theyare omitted instead, which is what
Event(-1)expects: both already default to''.How this was checked
On a default install, with
cal_allow_unlinkedleft untouched:year=2027;month=3;day=14opens the form on 2027-03-14 — previouslythat was ignored even when the fatal did not fire
board index
Then with
cal_allow_unlinkedenabled, to confirm the standalone editor still opensnormally. 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 beingviewed. 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.