Hook for address, phone, website and twitter


I’m writing a plugin (complementary to user_ldap) that integrates all user info with an LDAP base. I need a hook for getting changes in user attributes address, phone, website and twitter, but it do not seem to be available.

  1. Is there any hook for that?
  2. If not, is there any chance of intercepting the PUT request made to ./index.php/settings/users/{user}/settings, which contains the desired information?

The solution presented in How to create a new hook? works only for displayName and email.

thanks for the attention,

You can use:

$eventDispatcher = \OC::$server->getEventDispatcher();
$eventDispatcher->addListener('OC\AccountManager::userUpdated', /* your callback: ['OCA\App\Class', 'yourPublicStaticMethod'] */);

The method is called with an \Symfony\Component\EventDispatcher\GenericEvent argument.
If you call $event->getSubject() you get the IUser object.

Then grab the new data from the AccountManager or wait until we add the data to the event.

In NC 12+ you can also do $event->getArguments() to get the new data that was set.

Perfect! Thanks a lot!

Just for future reference, the code for getting user attributes is

$user = $event->getSubject();

$accountManager = new \OC\Accounts\AccountManager (                 
        \OC::$server->getEventDispatcher() );

$userData = $accountManager->getUser( $user );