You are here

user_event_dispatcher.module in Hook Event Dispatcher 3.x

Same filename and directory in other branches
  1. 8.2 modules/user_event_dispatcher/user_event_dispatcher.module

User event dispatcher submodule.

File

modules/user_event_dispatcher/user_event_dispatcher.module
View source
<?php

/**
 * @file
 * User event dispatcher submodule.
 */
use Drupal\Core\Session\AccountInterface;
use Drupal\user_event_dispatcher\Event\User\UserCancelEvent;
use Drupal\user_event_dispatcher\Event\User\UserCancelMethodsAlterEvent;
use Drupal\user_event_dispatcher\Event\User\UserFormatNameAlterEvent;
use Drupal\user_event_dispatcher\Event\User\UserLoginEvent;
use Drupal\user_event_dispatcher\Event\User\UserLogoutEvent;

/**
 * Implements hook_user_cancel().
 *
 * {@inheritdoc}
 */
function user_event_dispatcher_user_cancel(array $edit, AccountInterface $account, string $method) {

  /** @var \Drupal\hook_event_dispatcher\Manager\HookEventDispatcherManagerInterface $manager */
  $manager = Drupal::service('hook_event_dispatcher.manager');
  $event = new UserCancelEvent($edit, $account, $method);
  $manager
    ->register($event);
}

/**
 * Implements hook_user_cancel_methods_alter().
 *
 * {@inheritdoc}
 */
function user_event_dispatcher_user_cancel_methods_alter(array &$methods) {

  /** @var \Drupal\hook_event_dispatcher\Manager\HookEventDispatcherManagerInterface $manager */
  $manager = Drupal::service('hook_event_dispatcher.manager');
  $event = new UserCancelMethodsAlterEvent($methods);
  $manager
    ->register($event);
}

/**
 * Implements hook_user_login().
 *
 * {@inheritdoc}
 */
function user_event_dispatcher_user_login(AccountInterface $account) {

  /** @var \Drupal\hook_event_dispatcher\Manager\HookEventDispatcherManagerInterface $manager */
  $manager = Drupal::service('hook_event_dispatcher.manager');
  $event = new UserLoginEvent($account);
  $manager
    ->register($event);
}

/**
 * Implements hook_user_logout().
 *
 * {@inheritdoc}
 */
function user_event_dispatcher_user_logout(AccountInterface $account) {

  /** @var \Drupal\hook_event_dispatcher\Manager\HookEventDispatcherManagerInterface $manager */
  $manager = Drupal::service('hook_event_dispatcher.manager');
  $event = new UserLogoutEvent($account);
  $manager
    ->register($event);
}

/**
 * Implements hook_user_format_name_alter().
 *
 * {@inheritdoc}
 */
function user_event_dispatcher_user_format_name_alter(&$name, AccountInterface $account) {

  /** @var \Drupal\hook_event_dispatcher\Manager\HookEventDispatcherManagerInterface $manager */
  $manager = Drupal::service('hook_event_dispatcher.manager');
  $event = new UserFormatNameAlterEvent($name, $account);
  $manager
    ->register($event);
}