123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461 |
- <?php
- function hook_user_load($users) {
- $result = db_query('SELECT uid, foo FROM {my_table} WHERE uid IN (:uids)', array(':uids' => array_keys($users)));
- foreach ($result as $record) {
- $users[$record->uid]->foo = $record->foo;
- }
- }
- function hook_user_delete($account) {
- db_delete('mytable')
- ->condition('uid', $account->uid)
- ->execute();
- }
- function hook_user_cancel($edit, $account, $method) {
- switch ($method) {
- case 'user_cancel_block_unpublish':
-
- module_load_include('inc', 'node', 'node.admin');
- $nodes = db_select('node', 'n')
- ->fields('n', array('nid'))
- ->condition('uid', $account->uid)
- ->execute()
- ->fetchCol();
- node_mass_update($nodes, array('status' => 0));
- break;
- case 'user_cancel_reassign':
-
- module_load_include('inc', 'node', 'node.admin');
- $nodes = db_select('node', 'n')
- ->fields('n', array('nid'))
- ->condition('uid', $account->uid)
- ->execute()
- ->fetchCol();
- node_mass_update($nodes, array('uid' => 0));
-
- db_update('node_revision')
- ->fields(array('uid' => 0))
- ->condition('uid', $account->uid)
- ->execute();
-
- db_delete('history')
- ->condition('uid', $account->uid)
- ->execute();
- break;
- }
- }
- function hook_user_cancel_methods_alter(&$methods) {
-
- $methods['user_cancel_block_unpublish']['access'] = user_access('administer site configuration');
-
- unset($methods['user_cancel_reassign']);
-
- $methods['mymodule_zero_out'] = array(
- 'title' => t('Delete the account and remove all content.'),
- 'description' => t('All your content will be replaced by empty strings.'),
-
- 'access' => user_access('access zero-out account cancellation method'),
- );
- }
- function hook_user_operations() {
- $operations = array(
- 'unblock' => array(
- 'label' => t('Unblock the selected users'),
- 'callback' => 'user_user_operations_unblock',
- ),
- 'block' => array(
- 'label' => t('Block the selected users'),
- 'callback' => 'user_user_operations_block',
- ),
- 'cancel' => array(
- 'label' => t('Cancel the selected user accounts'),
- ),
- );
- return $operations;
- }
- function hook_user_categories() {
- return array(array(
- 'name' => 'account',
- 'title' => t('Account settings'),
- 'weight' => 1,
- ));
- }
- function hook_user_presave(&$edit, $account, $category) {
-
-
- if (isset($edit['mymodule_foo'])) {
- $edit['data']['mymodule_bar'] = $edit['mymodule_foo'];
- }
- }
- function hook_user_insert(&$edit, $account, $category) {
- db_insert('mytable')
- ->fields(array(
- 'myfield' => $edit['myfield'],
- 'uid' => $account->uid,
- ))
- ->execute();
- }
- function hook_user_update(&$edit, $account, $category) {
- db_insert('user_changes')
- ->fields(array(
- 'uid' => $account->uid,
- 'changed' => time(),
- ))
- ->execute();
- }
- function hook_user_login(&$edit, $account) {
-
- if (!$account->timezone && variable_get('configurable_timezones', 1) && variable_get('empty_timezone_message', 0)) {
- drupal_set_message(t('Configure your <a href="@user-edit">account time zone setting</a>.', array('@user-edit' => url("user/$account->uid/edit", array('query' => drupal_get_destination(), 'fragment' => 'edit-timezone')))));
- }
- }
- function hook_user_logout($account) {
- db_insert('logouts')
- ->fields(array(
- 'uid' => $account->uid,
- 'time' => time(),
- ))
- ->execute();
- }
- function hook_user_view($account, $view_mode, $langcode) {
- if (user_access('create blog content', $account)) {
- $account->content['summary']['blog'] = array(
- '#type' => 'user_profile_item',
- '#title' => t('Blog'),
- '#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)))))),
- '#attributes' => array('class' => array('blog')),
- );
- }
- }
- function hook_user_view_alter(&$build) {
-
- if (isset($build['an_additional_field'])) {
-
- $build['an_additional_field']['#weight'] = -10;
- }
-
- $build['#post_render'][] = 'my_module_user_post_render';
- }
- function hook_user_role_presave($role) {
-
- if (empty($role->uuid)) {
- $role->uuid = uuid_uuid();
- }
- }
- function hook_user_role_insert($role) {
-
- db_insert('my_module_table')
- ->fields(array(
- 'rid' => $role->rid,
- 'role_description' => $role->description,
- ))
- ->execute();
- }
- function hook_user_role_update($role) {
-
- db_merge('my_module_table')
- ->key(array('rid' => $role->rid))
- ->fields(array(
- 'role_description' => $role->description
- ))
- ->execute();
- }
- function hook_user_role_delete($role) {
-
- db_delete('my_module_table')
- ->condition('rid', $role->rid)
- ->execute();
- }
|