auto_login_url.module in Auto Login URL 8
Same filename and directory in other branches
Main file for auto_login_url module.
File
auto_login_url.moduleView source
<?php
/**
* @file
* Main file for auto_login_url module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function auto_login_url_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.auto_login_url':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('This is a module that creates auto login URLs on demand or with tokens.') . ' </p>';
return $output;
}
}
/**
* Wrapper function for AutoLoginUrlCreate::create().
*/
function auto_login_url_create($uid, $destination, $absolute = FALSE) {
$alu_service = \Drupal::service('auto_login_url.create');
return $alu_service
->create($uid, $destination, $absolute);
}
/**
* Wrapper function for AutoLoginUrlCreate::convertText().
*/
function auto_login_url_convert_text($uid, $text) {
$alu_service = \Drupal::service('auto_login_url.create');
return $alu_service
->convertText($uid, $text);
}
/**
* Implements hook_cron().
*/
function auto_login_url_cron() {
$config = \Drupal::config('auto_login_url.settings');
// Delete over one month auto logins.
$connection = \Drupal::database();
$connection
->delete('auto_login_url')
->condition('timestamp', time() - $config
->get('expiration'), '<=')
->execute();
}
/**
* Implements hook_token_info().
*/
function auto_login_url_token_info() {
// Add new tokens.
$info = [];
// Home token.
$info['tokens']['user']['auto-login-url-token'] = [
'name' => t('Auto Login URL'),
'description' => t('This an auto login token for the user.'),
];
// Link that goes to user edit page.
$info['tokens']['user']['auto-login-url-account-edit-token'] = [
'name' => t('Auto Login URL account edit'),
'description' => t('This an auto login for the user account page.'),
];
return $info;
}
/**
* Implements hook_tokens().
*/
function auto_login_url_tokens($type, $tokens, array $data = [], array $options = []) {
$replacements = [];
if ($type == 'user') {
$user = $data['user'];
foreach ($tokens as $name => $original) {
switch ($name) {
case 'auto-login-url-token':
$replacements[$original] = auto_login_url_create($user
->id(), '<front>', TRUE);
break;
case 'auto-login-url-account-edit-token':
$replacements[$original] = auto_login_url_create($user
->id(), 'user/' . $user
->id() . '/edit', TRUE);
break;
}
}
}
return $replacements;
}
Functions
Name | Description |
---|---|
auto_login_url_convert_text | Wrapper function for AutoLoginUrlCreate::convertText(). |
auto_login_url_create | Wrapper function for AutoLoginUrlCreate::create(). |
auto_login_url_cron | Implements hook_cron(). |
auto_login_url_help | Implements hook_help(). |
auto_login_url_tokens | Implements hook_tokens(). |
auto_login_url_token_info | Implements hook_token_info(). |