Closed timkelty closed 4 years ago
It doesn't look like it it listening for an author/authorId in the request either, so you'd have to do something like this:
Event::on(
GuestEntriesSaveController::class,
GuestEntriesSaveController::EVENT_BEFORE_SAVE_ENTRY,
function (GuestEntriesSaveEvent $event) {
$entry = $event->entry;
$currentUser = Craft::$app->getUser()->getIdentity();
if ($currentUser) {
$entry->authorId = $currentUser->id;
}
}
);
@timkelty Thank you for this! I was also trying to assign the currentUser
to the author (with no luck from the front-end <form>
). This did the trick!
Yeah the plugin isn’t concerned with the logged in user – the whole point is to provide a save-entry endpoint for guest users; if you have an entry saving form for logged-in users, ideally that is going through the entries/save-entry
controller, as demonstrated by the Entry Form example in the docs.
@brandonkelly yep - I think the use-case here is having a form that can do either - submit as a user or anonymous.
So, you could either do as I did above, or toggle the action to entries/save-entry
in your template based on currentUser
.
It is unclear from the docs if the author should be set for new entries if the user is logged in. Doesn't look like it currently does.