Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should author be set to logged-in user? #55

Closed
timkelty opened this issue Dec 23, 2019 · 4 comments
Closed

Should author be set to logged-in user? #55

timkelty opened this issue Dec 23, 2019 · 4 comments

Comments

@timkelty
Copy link

timkelty commented Dec 23, 2019

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.

@timkelty
Copy link
Author

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;
                }
            }
        );

@stursby
Copy link

stursby commented Feb 16, 2020

@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!

@brandonkelly
Copy link
Member

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.

@timkelty
Copy link
Author

timkelty commented Apr 7, 2020

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants