[3.0] Let the Post event button reach the event form - #9456
Open
albertlast wants to merge 1 commit into
Open
Conversation
The "Post event" button on a topic is a plain link, so the request that opens the form carries no post data at all. initiateEvent() nonetheless handed the request straight to Event::setRequestedStartAndDuration(), which insists on being given a date and fatals with "Invalid date." when it cannot find one, so the button never reached the form. Behind that sat a second one: the properties array named 'title' and 'location' unconditionally and gave them null when the request had not supplied them. Both are typed string on Event and already default to '', so the constructor rejected the null. Calendar::post() draws the unlinked version of this same form and has neither problem, because it just constructs Event(-1) and lets it fill in the defaults. Do the same here: only name the properties the request actually gave, and only ask for the requested start when the request carries one, which is what happens when a failed post is redisplayed. Signed-off-by: Mathias Albert <mathiaspapealbert@hotmail.com> 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
The Post event button on a topic (
?action=post;calendar;msg=N;topic=N.0, added byDisplay.php) has never reached the form. It fatals with "Invalid date.", every time, on every forum.Post::initiateEvent()hands the request toEvent::setRequestedStartAndDuration()before constructing the event. That helper is the one used when an event is saved, so it insists on being given a date and callsfatalLang('invalid_date')when it cannot find one. Nothing gives it one here: the button is a plain link, so there is no post data at all. (It only ever reads$_POST, so a date in the query string would not help either.)Removing that uncovered a second fatal in the same few lines. The properties array named
titleandlocationunconditionally, passingnullwhen the request had not supplied them:Event::$titleandEvent::$locationare bothpublic stringwith a''default, so the constructor rejects the null with "Cannot assign null to property SMF\Calendar\Event::$title of type string". Absent means''here, not null.Calendar::post()draws the unlinked version of this same form and has neither problem, because it simply doesnew Event(-1)and lets the constructor fill in the defaults. This makesinitiateEvent()behave the same way: name only the properties the request actually gave, and only ask for the requested start when the request carries one — which is exactly the case that matters, a failed post being redisplayed.There is a third one behind these two, already fixed in #9405: with both of the above out of the way the form next dies on "Object of type SMF\TimeInterval ... has not been correctly initialized" from
Event::__construct(). Both PRs are needed before the button works; they are independent and can land in either order.How this was tested
On a local 3.0 install, with #9405 merged in for the third fatal:
?action=post;calendar;msg=1;topic=1.0now draws the Post Event form, defaulting to now, with no console errors and nothing insmf_log_errors.id_topicandid_boardboth set), then redirects to the post.start_date=2027-03-04,start_time=09:30comes back with those values still in the fields, so the guard letssetRequestedStartAndDuration()run whenever the request actually has a date.Issues References (Fixes|Related|Closes)
Related: #9405