XF 2.2 User Save event listener - invalid class

CrispinP

Well-known member
Hi


I am trying to capture when a user saves their profile. I want to update a field when a custom value is changed.

I have my addon and what I think is correct class/method but I get an error
Callback Crispin\CountryAdjust\user::visitorSetup is invalid (error_invalid_class).

Code:
<?php

namespace Crispin\CA\Listener;

use XF\Mvc\Entity\Structure;

class User extends XFCP_User
{

    public static function visitorSetup(\XF\Entity\User &$visitor)
    {
        return true;   
    }
}

I've tried to plumb it in like this:
1622370716876.png


and my code is in src\AddOns\Crispin\CountryAdjust

Admittedly, all the above is copied from anther post here. Clearly I am missing something. :(
 

mcatze

Well-known member
When a user saves their profile i use this part. Its in src/addons/My/AddOn/Listener.php

PHP:
<?php

namespace My\AddOn;

use XF\Mvc\Entity\Entity;

class Listener
{
    public static function entityPreSaveUserProfile(\XF\Mvc\Entity\Entity $entity)
    {
        return something;
    }
}

Bildschirmfoto 2021-05-30 um 12.56.09.png
 

Lukas W.

Well-known member
You declared your namespace as \Crispin\CA\Listener\User, but are using \Crispin\CountryAdjust\User in your declaration.

Also visitorSetup is the wrong event. You want entity pre save with event hint XF:User and/or XF:UserProfile
 

Kirby

Well-known member
... and a listener method normally should not be in a class extension.

If this is the only method the class extension does define, this would also not be compliant with the resource standards.

Last but not least you would also need to define this class extension if you really want to have the listener in the extension class, just defining the listener won't be enough in this case.
 
Top