123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?php
- use Drupal\Core\Session\AccountInterface;
- use Drupal\user\UserInterface;
- function hook_user_cancel($edit, UserInterface $account, $method) {
- switch ($method) {
- case 'user_cancel_block_unpublish':
-
- module_load_include('inc', 'node', 'node.admin');
- $nodes = \Drupal::entityQuery('node')
- ->condition('uid', $account->id())
- ->execute();
- node_mass_update($nodes, ['status' => 0], NULL, TRUE);
- break;
- case 'user_cancel_reassign':
-
- module_load_include('inc', 'node', 'node.admin');
- $nodes = \Drupal::entityQuery('node')
- ->condition('uid', $account->id())
- ->execute();
- node_mass_update($nodes, ['uid' => 0], NULL, TRUE);
-
- db_update('node_field_revision')
- ->fields(['uid' => 0])
- ->condition('uid', $account->id())
- ->execute();
- break;
- }
- }
- function hook_user_cancel_methods_alter(&$methods) {
- $account = \Drupal::currentUser();
-
- $methods['user_cancel_block_unpublish']['access'] = $account->hasPermission('administer site configuration');
-
- unset($methods['user_cancel_reassign']);
-
- $methods['mymodule_zero_out'] = [
- 'title' => t('Delete the account and remove all content.'),
- 'description' => t('All your content will be replaced by empty strings.'),
-
- 'access' => $account->hasPermission('access zero-out account cancellation method'),
- ];
- }
- function hook_user_format_name_alter(&$name, AccountInterface $account) {
-
- if ($account->id()) {
- $name = t('User @uid', ['@uid' => $account->id()]);
- }
- }
- function hook_user_login(UserInterface $account) {
- $config = \Drupal::config('system.date');
-
- if (!$account->getTimezone() && $config->get('timezone.user.configurable') && $config->get('timezone.user.warn')) {
- \Drupal::messenger()
- ->addStatus(t('Configure your <a href=":user-edit">account time zone setting</a>.', [
- ':user-edit' => $account->url('edit-form', [
- 'query' => \Drupal::destination()
- ->getAsArray(),
- 'fragment' => 'edit-timezone',
- ]),
- ]));
- }
- }
- function hook_user_logout(AccountInterface $account) {
- db_insert('logouts')
- ->fields([
- 'uid' => $account->id(),
- 'time' => time(),
- ])
- ->execute();
- }
|