eus-8.x-1.x-dev/eus.module
eus.module
<?php
/**
* @file
* End User Session.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;
/**
* Implements hook_help().
*/
function eus_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the ctc module.
case 'help.page.eus':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t("Admin can destroy any user session from interface.") . '</p>';
return $output;
}
}
/**
* Implements hook_entity_operation().
*/
function eus_entity_operation(EntityInterface $entity) {
$current_user_id = \Drupal::currentUser()->id();
// For single user.
if (in_array($entity->bundle(), ['user']) && $current_user_id != $entity->id()) {
$operations = [];
$operations['end_session'] = [
'title' => t('End User Session'),
'url' => Url::fromRoute('eus.destroy_confirm', ['user' => $entity->id()]),
'weight' => 151,
];
return $operations;
}
// For All users for a particular role.
if (in_array($entity->bundle(), ['user_role']) && !in_array($entity->id(), ['anonymous'])) {
$operations = [];
$operations['end_users_session'] = [
'title' => t('End Users Session'),
'url' => Url::fromRoute('eus.destroy_role_confirm', ['role' => $entity->id()]),
'weight' => 151,
];
return $operations;
}
}
