danielebarchiesi@0: array_keys($users))); danielebarchiesi@0: foreach ($result as $record) { danielebarchiesi@0: $users[$record->uid]->foo = $record->foo; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Respond to user deletion. danielebarchiesi@0: * danielebarchiesi@0: * This hook is invoked from user_delete_multiple() before field_attach_delete() danielebarchiesi@0: * is called and before users are actually removed from the database. danielebarchiesi@0: * danielebarchiesi@0: * Modules should additionally implement hook_user_cancel() to process stored danielebarchiesi@0: * user data for other account cancellation methods. danielebarchiesi@0: * danielebarchiesi@0: * @param $account danielebarchiesi@0: * The account that is being deleted. danielebarchiesi@0: * danielebarchiesi@0: * @see user_delete_multiple() danielebarchiesi@0: */ danielebarchiesi@0: function hook_user_delete($account) { danielebarchiesi@0: db_delete('mytable') danielebarchiesi@0: ->condition('uid', $account->uid) danielebarchiesi@0: ->execute(); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Act on user account cancellations. danielebarchiesi@0: * danielebarchiesi@0: * This hook is invoked from user_cancel() before a user account is canceled. danielebarchiesi@0: * Depending on the account cancellation method, the module should either do danielebarchiesi@0: * nothing, unpublish content, or anonymize content. See user_cancel_methods() danielebarchiesi@0: * for the list of default account cancellation methods provided by User module. danielebarchiesi@0: * Modules may add further methods via hook_user_cancel_methods_alter(). danielebarchiesi@0: * danielebarchiesi@0: * This hook is NOT invoked for the 'user_cancel_delete' account cancellation danielebarchiesi@0: * method. To react on this method, implement hook_user_delete() instead. danielebarchiesi@0: * danielebarchiesi@0: * Expensive operations should be added to the global account cancellation batch danielebarchiesi@0: * by using batch_set(). danielebarchiesi@0: * danielebarchiesi@0: * @param $edit danielebarchiesi@0: * The array of form values submitted by the user. danielebarchiesi@0: * @param $account danielebarchiesi@0: * The user object on which the operation is being performed. danielebarchiesi@0: * @param $method danielebarchiesi@0: * The account cancellation method. danielebarchiesi@0: * danielebarchiesi@0: * @see user_cancel_methods() danielebarchiesi@0: * @see hook_user_cancel_methods_alter() danielebarchiesi@0: */ danielebarchiesi@0: function hook_user_cancel($edit, $account, $method) { danielebarchiesi@0: switch ($method) { danielebarchiesi@0: case 'user_cancel_block_unpublish': danielebarchiesi@0: // Unpublish nodes (current revisions). danielebarchiesi@0: module_load_include('inc', 'node', 'node.admin'); danielebarchiesi@0: $nodes = db_select('node', 'n') danielebarchiesi@0: ->fields('n', array('nid')) danielebarchiesi@0: ->condition('uid', $account->uid) danielebarchiesi@0: ->execute() danielebarchiesi@0: ->fetchCol(); danielebarchiesi@0: node_mass_update($nodes, array('status' => 0)); danielebarchiesi@0: break; danielebarchiesi@0: danielebarchiesi@0: case 'user_cancel_reassign': danielebarchiesi@0: // Anonymize nodes (current revisions). danielebarchiesi@0: module_load_include('inc', 'node', 'node.admin'); danielebarchiesi@0: $nodes = db_select('node', 'n') danielebarchiesi@0: ->fields('n', array('nid')) danielebarchiesi@0: ->condition('uid', $account->uid) danielebarchiesi@0: ->execute() danielebarchiesi@0: ->fetchCol(); danielebarchiesi@0: node_mass_update($nodes, array('uid' => 0)); danielebarchiesi@0: // Anonymize old revisions. danielebarchiesi@0: db_update('node_revision') danielebarchiesi@0: ->fields(array('uid' => 0)) danielebarchiesi@0: ->condition('uid', $account->uid) danielebarchiesi@0: ->execute(); danielebarchiesi@0: // Clean history. danielebarchiesi@0: db_delete('history') danielebarchiesi@0: ->condition('uid', $account->uid) danielebarchiesi@0: ->execute(); danielebarchiesi@0: break; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Modify account cancellation methods. danielebarchiesi@0: * danielebarchiesi@0: * By implementing this hook, modules are able to add, customize, or remove danielebarchiesi@0: * account cancellation methods. All defined methods are turned into radio danielebarchiesi@0: * button form elements by user_cancel_methods() after this hook is invoked. danielebarchiesi@0: * The following properties can be defined for each method: danielebarchiesi@0: * - title: The radio button's title. danielebarchiesi@0: * - description: (optional) A description to display on the confirmation form danielebarchiesi@0: * if the user is not allowed to select the account cancellation method. The danielebarchiesi@0: * description is NOT used for the radio button, but instead should provide danielebarchiesi@0: * additional explanation to the user seeking to cancel their account. danielebarchiesi@0: * - access: (optional) A boolean value indicating whether the user can access danielebarchiesi@0: * a method. If #access is defined, the method cannot be configured as default danielebarchiesi@0: * method. danielebarchiesi@0: * danielebarchiesi@0: * @param $methods danielebarchiesi@0: * An array containing user account cancellation methods, keyed by method id. danielebarchiesi@0: * danielebarchiesi@0: * @see user_cancel_methods() danielebarchiesi@0: * @see user_cancel_confirm_form() danielebarchiesi@0: */ danielebarchiesi@0: function hook_user_cancel_methods_alter(&$methods) { danielebarchiesi@0: // Limit access to disable account and unpublish content method. danielebarchiesi@0: $methods['user_cancel_block_unpublish']['access'] = user_access('administer site configuration'); danielebarchiesi@0: danielebarchiesi@0: // Remove the content re-assigning method. danielebarchiesi@0: unset($methods['user_cancel_reassign']); danielebarchiesi@0: danielebarchiesi@0: // Add a custom zero-out method. danielebarchiesi@0: $methods['mymodule_zero_out'] = array( danielebarchiesi@0: 'title' => t('Delete the account and remove all content.'), danielebarchiesi@0: 'description' => t('All your content will be replaced by empty strings.'), danielebarchiesi@0: // access should be used for administrative methods only. danielebarchiesi@0: 'access' => user_access('access zero-out account cancellation method'), danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Add mass user operations. danielebarchiesi@0: * danielebarchiesi@0: * This hook enables modules to inject custom operations into the mass operations danielebarchiesi@0: * dropdown found at admin/people, by associating a callback function with danielebarchiesi@0: * the operation, which is called when the form is submitted. The callback function danielebarchiesi@0: * receives one initial argument, which is an array of the checked users. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An array of operations. Each operation is an associative array that may danielebarchiesi@0: * contain the following key-value pairs: danielebarchiesi@0: * - "label": Required. The label for the operation, displayed in the dropdown menu. danielebarchiesi@0: * - "callback": Required. The function to call for the operation. danielebarchiesi@0: * - "callback arguments": Optional. An array of additional arguments to pass to danielebarchiesi@0: * the callback function. danielebarchiesi@0: * danielebarchiesi@0: */ danielebarchiesi@0: function hook_user_operations() { danielebarchiesi@0: $operations = array( danielebarchiesi@0: 'unblock' => array( danielebarchiesi@0: 'label' => t('Unblock the selected users'), danielebarchiesi@0: 'callback' => 'user_user_operations_unblock', danielebarchiesi@0: ), danielebarchiesi@0: 'block' => array( danielebarchiesi@0: 'label' => t('Block the selected users'), danielebarchiesi@0: 'callback' => 'user_user_operations_block', danielebarchiesi@0: ), danielebarchiesi@0: 'cancel' => array( danielebarchiesi@0: 'label' => t('Cancel the selected user accounts'), danielebarchiesi@0: ), danielebarchiesi@0: ); danielebarchiesi@0: return $operations; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Retrieve a list of user setting or profile information categories. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An array of associative arrays. Each inner array has elements: danielebarchiesi@0: * - "name": The internal name of the category. danielebarchiesi@0: * - "title": The human-readable, localized name of the category. danielebarchiesi@0: * - "weight": An integer specifying the category's sort ordering. danielebarchiesi@0: * - "access callback": Name of the access callback function to use to danielebarchiesi@0: * determine whether the user can edit the category. Defaults to using danielebarchiesi@0: * user_edit_access(). See hook_menu() for more information on access danielebarchiesi@0: * callbacks. danielebarchiesi@0: * - "access arguments": Arguments for the access callback function. Defaults danielebarchiesi@0: * to array(1). danielebarchiesi@0: */ danielebarchiesi@0: function hook_user_categories() { danielebarchiesi@0: return array(array( danielebarchiesi@0: 'name' => 'account', danielebarchiesi@0: 'title' => t('Account settings'), danielebarchiesi@0: 'weight' => 1, danielebarchiesi@0: )); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * A user account is about to be created or updated. danielebarchiesi@0: * danielebarchiesi@0: * This hook is primarily intended for modules that want to store properties in danielebarchiesi@0: * the serialized {users}.data column, which is automatically loaded whenever a danielebarchiesi@0: * user account object is loaded, modules may add to $edit['data'] in order danielebarchiesi@0: * to have their data serialized on save. danielebarchiesi@0: * danielebarchiesi@0: * @param $edit danielebarchiesi@0: * The array of form values submitted by the user. Assign values to this danielebarchiesi@0: * array to save changes in the database. danielebarchiesi@0: * @param $account danielebarchiesi@0: * The user object on which the operation is performed. Values assigned in danielebarchiesi@0: * this object will not be saved in the database. danielebarchiesi@0: * @param $category danielebarchiesi@0: * The active category of user information being edited. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_user_insert() danielebarchiesi@0: * @see hook_user_update() danielebarchiesi@0: */ danielebarchiesi@0: function hook_user_presave(&$edit, $account, $category) { danielebarchiesi@0: // Make sure that our form value 'mymodule_foo' is stored as danielebarchiesi@0: // 'mymodule_bar' in the 'data' (serialized) column. danielebarchiesi@0: if (isset($edit['mymodule_foo'])) { danielebarchiesi@0: $edit['data']['mymodule_bar'] = $edit['mymodule_foo']; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * A user account was created. danielebarchiesi@0: * danielebarchiesi@0: * The module should save its custom additions to the user object into the danielebarchiesi@0: * database. danielebarchiesi@0: * danielebarchiesi@0: * @param $edit danielebarchiesi@0: * The array of form values submitted by the user. danielebarchiesi@0: * @param $account danielebarchiesi@0: * The user object on which the operation is being performed. danielebarchiesi@0: * @param $category danielebarchiesi@0: * The active category of user information being edited. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_user_presave() danielebarchiesi@0: * @see hook_user_update() danielebarchiesi@0: */ danielebarchiesi@0: function hook_user_insert(&$edit, $account, $category) { danielebarchiesi@0: db_insert('mytable') danielebarchiesi@0: ->fields(array( danielebarchiesi@0: 'myfield' => $edit['myfield'], danielebarchiesi@0: 'uid' => $account->uid, danielebarchiesi@0: )) danielebarchiesi@0: ->execute(); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * A user account was updated. danielebarchiesi@0: * danielebarchiesi@0: * Modules may use this hook to update their user data in a custom storage danielebarchiesi@0: * after a user account has been updated. danielebarchiesi@0: * danielebarchiesi@0: * @param $edit danielebarchiesi@0: * The array of form values submitted by the user. danielebarchiesi@0: * @param $account danielebarchiesi@0: * The user object on which the operation is performed. danielebarchiesi@0: * @param $category danielebarchiesi@0: * The active category of user information being edited. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_user_presave() danielebarchiesi@0: * @see hook_user_insert() danielebarchiesi@0: */ danielebarchiesi@0: function hook_user_update(&$edit, $account, $category) { danielebarchiesi@0: db_insert('user_changes') danielebarchiesi@0: ->fields(array( danielebarchiesi@0: 'uid' => $account->uid, danielebarchiesi@0: 'changed' => time(), danielebarchiesi@0: )) danielebarchiesi@0: ->execute(); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * The user just logged in. danielebarchiesi@0: * danielebarchiesi@0: * @param $edit danielebarchiesi@0: * The array of form values submitted by the user. danielebarchiesi@0: * @param $account danielebarchiesi@0: * The user object on which the operation was just performed. danielebarchiesi@0: */ danielebarchiesi@0: function hook_user_login(&$edit, $account) { danielebarchiesi@0: // If the user has a NULL time zone, notify them to set a time zone. danielebarchiesi@0: if (!$account->timezone && variable_get('configurable_timezones', 1) && variable_get('empty_timezone_message', 0)) { danielebarchiesi@0: drupal_set_message(t('Configure your account time zone setting.', array('@user-edit' => url("user/$account->uid/edit", array('query' => drupal_get_destination(), 'fragment' => 'edit-timezone'))))); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * The user just logged out. danielebarchiesi@0: * danielebarchiesi@0: * Note that when this hook is invoked, the changes have not yet been written to danielebarchiesi@0: * the database, because a database transaction is still in progress. The danielebarchiesi@0: * transaction is not finalized until the save operation is entirely completed danielebarchiesi@0: * and user_save() goes out of scope. You should not rely on data in the danielebarchiesi@0: * database at this time as it is not updated yet. You should also note that any danielebarchiesi@0: * write/update database queries executed from this hook are also not committed danielebarchiesi@0: * immediately. Check user_save() and db_transaction() for more info. danielebarchiesi@0: * danielebarchiesi@0: * @param $account danielebarchiesi@0: * The user object on which the operation was just performed. danielebarchiesi@0: */ danielebarchiesi@0: function hook_user_logout($account) { danielebarchiesi@0: db_insert('logouts') danielebarchiesi@0: ->fields(array( danielebarchiesi@0: 'uid' => $account->uid, danielebarchiesi@0: 'time' => time(), danielebarchiesi@0: )) danielebarchiesi@0: ->execute(); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * The user's account information is being displayed. danielebarchiesi@0: * danielebarchiesi@0: * The module should format its custom additions for display and add them to the danielebarchiesi@0: * $account->content array. danielebarchiesi@0: * danielebarchiesi@0: * Note that when this hook is invoked, the changes have not yet been written to danielebarchiesi@0: * the database, because a database transaction is still in progress. The danielebarchiesi@0: * transaction is not finalized until the save operation is entirely completed danielebarchiesi@0: * and user_save() goes out of scope. You should not rely on data in the danielebarchiesi@0: * database at this time as it is not updated yet. You should also note that any danielebarchiesi@0: * write/update database queries executed from this hook are also not committed danielebarchiesi@0: * immediately. Check user_save() and db_transaction() for more info. danielebarchiesi@0: * danielebarchiesi@0: * @param $account danielebarchiesi@0: * The user object on which the operation is being performed. danielebarchiesi@0: * @param $view_mode danielebarchiesi@0: * View mode, e.g. 'full'. danielebarchiesi@0: * @param $langcode danielebarchiesi@0: * The language code used for rendering. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_user_view_alter() danielebarchiesi@0: * @see hook_entity_view() danielebarchiesi@0: */ danielebarchiesi@0: function hook_user_view($account, $view_mode, $langcode) { danielebarchiesi@0: if (user_access('create blog content', $account)) { danielebarchiesi@0: $account->content['summary']['blog'] = array( danielebarchiesi@0: '#type' => 'user_profile_item', danielebarchiesi@0: '#title' => t('Blog'), danielebarchiesi@0: '#markup' => l(t('View recent blog entries'), "blog/$account->uid", array('attributes' => array('title' => t("Read !username's latest blog entries.", array('!username' => format_username($account)))))), danielebarchiesi@0: '#attributes' => array('class' => array('blog')), danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * The user was built; the module may modify the structured content. danielebarchiesi@0: * danielebarchiesi@0: * This hook is called after the content has been assembled in a structured array danielebarchiesi@0: * and may be used for doing processing which requires that the complete user danielebarchiesi@0: * content structure has been built. danielebarchiesi@0: * danielebarchiesi@0: * If the module wishes to act on the rendered HTML of the user rather than the danielebarchiesi@0: * structured content array, it may use this hook to add a #post_render callback. danielebarchiesi@0: * Alternatively, it could also implement hook_preprocess_user_profile(). See danielebarchiesi@0: * drupal_render() and theme() documentation respectively for details. danielebarchiesi@0: * danielebarchiesi@0: * @param $build danielebarchiesi@0: * A renderable array representing the user. danielebarchiesi@0: * danielebarchiesi@0: * @see user_view() danielebarchiesi@0: * @see hook_entity_view_alter() danielebarchiesi@0: */ danielebarchiesi@0: function hook_user_view_alter(&$build) { danielebarchiesi@0: // Check for the existence of a field added by another module. danielebarchiesi@0: if (isset($build['an_additional_field'])) { danielebarchiesi@0: // Change its weight. danielebarchiesi@0: $build['an_additional_field']['#weight'] = -10; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // Add a #post_render callback to act on the rendered HTML of the user. danielebarchiesi@0: $build['#post_render'][] = 'my_module_user_post_render'; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Inform other modules that a user role is about to be saved. danielebarchiesi@0: * danielebarchiesi@0: * Modules implementing this hook can act on the user role object before danielebarchiesi@0: * it has been saved to the database. danielebarchiesi@0: * danielebarchiesi@0: * @param $role danielebarchiesi@0: * A user role object. danielebarchiesi@0: * danielebarchiesi@0: * @see hook_user_role_insert() danielebarchiesi@0: * @see hook_user_role_update() danielebarchiesi@0: */ danielebarchiesi@0: function hook_user_role_presave($role) { danielebarchiesi@0: // Set a UUID for the user role if it doesn't already exist danielebarchiesi@0: if (empty($role->uuid)) { danielebarchiesi@0: $role->uuid = uuid_uuid(); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Inform other modules that a user role has been added. danielebarchiesi@0: * danielebarchiesi@0: * Modules implementing this hook can act on the user role object when saved to danielebarchiesi@0: * the database. It's recommended that you implement this hook if your module danielebarchiesi@0: * adds additional data to user roles object. The module should save its custom danielebarchiesi@0: * additions to the database. danielebarchiesi@0: * danielebarchiesi@0: * @param $role danielebarchiesi@0: * A user role object. danielebarchiesi@0: */ danielebarchiesi@0: function hook_user_role_insert($role) { danielebarchiesi@0: // Save extra fields provided by the module to user roles. danielebarchiesi@0: db_insert('my_module_table') danielebarchiesi@0: ->fields(array( danielebarchiesi@0: 'rid' => $role->rid, danielebarchiesi@0: 'role_description' => $role->description, danielebarchiesi@0: )) danielebarchiesi@0: ->execute(); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Inform other modules that a user role has been updated. danielebarchiesi@0: * danielebarchiesi@0: * Modules implementing this hook can act on the user role object when updated. danielebarchiesi@0: * It's recommended that you implement this hook if your module adds additional danielebarchiesi@0: * data to user roles object. The module should save its custom additions to danielebarchiesi@0: * the database. danielebarchiesi@0: * danielebarchiesi@0: * @param $role danielebarchiesi@0: * A user role object. danielebarchiesi@0: */ danielebarchiesi@0: function hook_user_role_update($role) { danielebarchiesi@0: // Save extra fields provided by the module to user roles. danielebarchiesi@0: db_merge('my_module_table') danielebarchiesi@0: ->key(array('rid' => $role->rid)) danielebarchiesi@0: ->fields(array( danielebarchiesi@0: 'role_description' => $role->description danielebarchiesi@0: )) danielebarchiesi@0: ->execute(); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Inform other modules that a user role has been deleted. danielebarchiesi@0: * danielebarchiesi@0: * This hook allows you act when a user role has been deleted. danielebarchiesi@0: * If your module stores references to roles, it's recommended that you danielebarchiesi@0: * implement this hook and delete existing instances of the deleted role danielebarchiesi@0: * in your module database tables. danielebarchiesi@0: * danielebarchiesi@0: * @param $role danielebarchiesi@0: * The $role object being deleted. danielebarchiesi@0: */ danielebarchiesi@0: function hook_user_role_delete($role) { danielebarchiesi@0: // Delete existing instances of the deleted role. danielebarchiesi@0: db_delete('my_module_table') danielebarchiesi@0: ->condition('rid', $role->rid) danielebarchiesi@0: ->execute(); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * @} End of "addtogroup hooks". danielebarchiesi@0: */