hello everyone,
i am having some issues with this hook. what i am trying to do:
- i create a user programatically
- after the creation i want to call the update function so even empty fields are created in the content file, for instance for when the user gets exported in a CSV file these empty fields are also available
- in the update function i also manipulate the data a bit, so i created an extra class/model for my user
this is my code
class MemberUser extends User
{
public function update(array $input = null, string $languageCode = null, bool $validate = false): static
{
kirbylog(get_class($this)); // this gives me MemberUser
// ... here i manipulate a bit the $input array
return parent::update($input);
}
}
in my plugin i add this model of course
'userModels' => [
'member' => MemberUser::class
],
My hook looks like this
'user.create:after' => function ($user) {
if ($user->role() == 'member') { // this if is irrelevant, just to filter all other user roles out so they skip this whole thing
kirbylog(get_class($user)); // this gives me only Kirby\Cms\User
// to create all fields, also empty ones, and do the input manipulations
$saveduser = $user->update();
}
}
as you can see i am logging the class of my user using kirbylog(). in the model the class output is MemberUser
. in the create:after hook its only User
though, which means my overwritten update() is not getting called.
by the way, if i kirbylog() the class in a user:update:after hook, it also gives me MemberUser
.
'user.update:after' => function (Kirby\Cms\User $newUser, Kirby\Cms\User $oldUser) {
kirbylog(get_class($newUser)); // this also gives me MemberUser
},
someone any ideas? :-/