function uc_role_user_view in Ubercart 8.4
Implements hook_user_view().
File
- uc_role/
uc_role.module, line 314 - Grants roles upon accepted payment of products.
Code
function uc_role_user_view(array &$build, UserInterface $account, EntityViewDisplayInterface $display, $view_mode) {
$user = \Drupal::currentUser();
// Only show if this user can access all role expirations, or if it's the same
// user and the expirations are showing on the user pages.
// Kick out anonymous or other view modes.
$show_expiration = \Drupal::config('uc_role.settings')
->get('default_show_expiration');
if ($view_mode == 'full' && $user
->isAuthenticated() && ($user
->id() == $account
->id() && $show_expiration || $user
->hasPermission('view all role expirations'))) {
$connection = \Drupal::database();
$expirations = $connection
->query('SELECT * FROM {uc_roles_expirations} WHERE uid = :uid', [
':uid' => $account
->id(),
]);
foreach ($expirations as $expiration) {
$build['uc_role'][$expiration->rid] = [
'#type' => 'item',
'#title' => _uc_role_get_name($expiration->rid),
'#markup' => t('This role will expire on @date', [
'@date' => \Drupal::service('date.formatter')
->format($expiration->expiration, 'short'),
]),
];
}
if (isset($build['uc_role'])) {
// There are role expirations, so need a container.
$build['uc_role'] += [
'#type' => 'item',
'#weight' => '-1',
'#title' => t('Expiring roles'),
];
}
}
}