studieren-ohne-grenzen / sogintegration

Drupal Module creating new user accounts, integrating them into our systems and sending notifications
1 stars 0 forks source link

Update email field in LDAP when saving user profile #2

Closed leomelzer closed 9 years ago

leomelzer commented 9 years ago

The appropriate hook is https://api.drupal.org/api/drupal/modules!user!user.api.php/function/hook_user_update/7

So

function sogintegration_user_update(&$edit, $account, $category) {
  // instantiate API
  // call appropriate method to change mail-alternative
}

@sebastian-leidig Right now no values seem to get saved at all when posting the profile form?

sleidig commented 9 years ago

no values are saved when posting the profile form: I stumbled over the reason: The field "Bundesland" is required but often still empty. If you don't fill it, the profile is not saved at all (although there is no error message anywhere ...)

leomelzer commented 9 years ago

Thanks, sounds plausible. Can you look into it or do we solve this some other time?

sleidig commented 9 years ago

Workaround for the time being: "Bundesland" is no longer a required field.

The form still doesn't save if other required fields are left empty or deleted despite showing a message "The changes have been saved." but this should happen less often during normal use.

added an issue, so we won't forget: #3

sleidig commented 9 years ago

@leomelzer Does it make sense to use some ldap library like you do in the dashboard? Or even call a Dashboard Api function to save the mail to ldap? (That would encapsulate the ldap structure in the dashboard only)

leomelzer commented 9 years ago

@sebastian-leidig I'd call the API by adding a function to the sogintegration.module like this (pseudocode...):

function sogintegration_user_update(&$edit, $account, $category) {
  // instantiate API
  include 'config.php';
  $api = new DashboardApi($dashboard_config);
  // call appropriate method to change mail-alternative
  $api->updateAlternativeMail($account['uid'], $edit['mail']);
}

Then we keep the write access to the LDAP tree mostly within the Dashboard component.

sleidig commented 9 years ago

Cool, I'll stick to this API method signature then.

leomelzer commented 9 years ago

API method implemented as of https://github.com/studieren-ohne-grenzen/dashboard/commit/16e9535848c0146f1b59f25006523caee69412c9

sleidig commented 9 years ago

To make this more general and also recognize people editing their details through the CiviCRM UI itself, I'll use hook_civicrm_post instead:

hook_civicrm_post( $op, $objectName, $objectId, &$objectRef )

http://wiki.civicrm.org/confluence/display/CRMDOC40/CiviCRM+hook+specification#CiviCRMhookspecification-hook_civicrm_post