<?php
use Drupal\Component\Utility\Crypt;
use Drupal\Core\Database\Query\SelectInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\comment\Plugin\Core\Entity\Comment;
use Drupal\entity\Plugin\Core\Entity\EntityDisplay;
use Drupal\file\Plugin\Core\Entity\File;
use Drupal\user\Plugin\Core\Entity\User;
use Drupal\user\UserInterface;
use Drupal\user\UserRole;
use Drupal\user\RoleInterface;
use Drupal\Core\Template\Attribute;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Drupal\menu_link\Plugin\Core\Entity\MenuLink;
const USERNAME_MAX_LENGTH = 60;
const EMAIL_MAX_LENGTH = 254;
const USER_REGISTER_ADMINISTRATORS_ONLY = 'admin_only';
const USER_REGISTER_VISITORS = 'visitors';
const USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL = 'visitors_admin_approval';
function user_help($path, $arg) {
global $user;
switch ($path) {
case 'admin/help#user':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The User module allows users to register, log in, and log out. It also allows users with proper permissions to manage user roles (used to classify users) and permissions associated with those roles. For more information, see the online handbook entry for <a href="@user">User module</a>.', array(
'@user' => 'http://drupal.org/documentation/modules/user',
)) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Creating and managing users') . '</dt>';
$output .= '<dd>' . t('The User module allows users with the appropriate <a href="@permissions">permissions</a> to create user accounts through the <a href="@people">People administration page</a>, where they can also assign users to one or more roles, and block or delete user accounts. If allowed, users without accounts (anonymous users) can create their own accounts on the <a href="@register">Create new account</a> page.', array(
'@permissions' => url('admin/people/permissions', array(
'fragment' => 'module-user',
)),
'@people' => url('admin/people'),
'@register' => url('user/register'),
)) . '</dd>';
$output .= '<dt>' . t('User roles and permissions') . '</dt>';
$output .= '<dd>' . t('<em>Roles</em> are used to group and classify users; each user can be assigned one or more roles. By default there are two roles: <em>anonymous user</em> (users that are not logged in) and <em>authenticated user</em> (users that are registered and logged in). Depending on choices you made when you installed Drupal, the installation process may have defined more roles, and you can create additional custom roles on the <a href="@roles">Roles page</a>. After creating roles, you can set permissions for each role on the <a href="@permissions_user">Permissions page</a>. Granting a permission allows users who have been assigned a particular role to perform an action on the site, such as viewing a particular type of content, editing or creating content, administering settings for a particular module, or using a particular function of the site (such as search).', array(
'@permissions_user' => url('admin/people/permissions'),
'@roles' => url('admin/people/roles'),
)) . '</dd>';
$output .= '<dt>' . t('Account settings') . '</dt>';
$output .= '<dd>' . t('The <a href="@accounts">Account settings page</a> allows you to manage settings for the displayed name of the anonymous user role, personal contact forms, user registration, and account cancellation. On this page you can also manage settings for account personalization (including signatures), and adapt the text for the e-mail messages that are sent automatically during the user registration process.', array(
'@accounts' => url('admin/config/people/accounts'),
)) . '</dd>';
$output .= '</dl>';
return $output;
case 'admin/people/create':
return '<p>' . t("This web page allows administrators to register new users. Users' e-mail addresses and usernames must be unique.") . '</p>';
case 'admin/people/permissions':
return '<p>' . t('Permissions let you control what users can do and see on your site. You can define a specific set of permissions for each role. (See the <a href="@role">Roles</a> page to create a role). Two important roles to consider are Authenticated Users and Administrators. Any permissions granted to the Authenticated Users role will be given to any user who can log into your site. You can make any role the Administrator role for the site, meaning this will be granted all new permissions automatically. You can do this on the <a href="@settings">User Settings</a> page. You should be careful to ensure that only trusted users are given this access and level of control of your site.', array(
'@role' => url('admin/people/roles'),
'@settings' => url('admin/config/people/accounts'),
)) . '</p>';
case 'admin/people/roles':
$output = '<p>' . t('Roles allow you to fine tune the security and administration of Drupal. A role defines a group of users that have certain privileges as defined on the <a href="@permissions">permissions page</a>. Examples of roles include: anonymous user, authenticated user, moderator, administrator and so on. In this area you will define the names and order of the roles on your site. It is recommended to order your roles from least permissive (anonymous user) to most permissive (administrator). To delete a role choose "edit role".', array(
'@permissions' => url('admin/people/permissions'),
)) . '</p>';
$output .= '<p>' . t('Drupal has three special user roles:') . '</p>';
$output .= '<ul>';
$output .= '<li>' . t("Anonymous user: this role is used for users that don't have a user account or that are not authenticated.") . '</li>';
$output .= '<li>' . t('Authenticated user: this role is automatically granted to all logged in users.') . '</li>';
$output .= '<li>' . t('Administrator role: this role is automatically granted all new permissions when you install a new module. Configure which role is the administrator role on the <a href="@account_settings">Account settings page</a>.', array(
'@account_settings' => url('admin/config/people/accounts'),
)) . '</li>';
$output .= '</ul>';
return $output;
case 'admin/config/people/accounts/fields':
return '<p>' . t('This form lets administrators add, edit, and arrange fields for storing user data.') . '</p>';
case 'admin/config/people/accounts/display':
return '<p>' . t('This form lets administrators configure how fields should be displayed when rendering a user profile page.') . '</p>';
case 'admin/people/search':
return '<p>' . t('Enter a simple pattern ("*" may be used as a wildcard match) to search for a username or e-mail address. For example, one may search for "br" and Drupal might return "brian", "brad", and "brenda@example.com".') . '</p>';
}
}
function user_theme() {
return array(
'user' => array(
'render element' => 'elements',
'file' => 'user.pages.inc',
'template' => 'user',
),
'user_admin_permissions' => array(
'render element' => 'form',
'file' => 'user.admin.inc',
),
'user_permission_description' => array(
'variables' => array(
'permission_item' => NULL,
'hide' => NULL,
),
'file' => 'user.admin.inc',
),
'user_signature' => array(
'variables' => array(
'signature' => NULL,
),
),
'username' => array(
'variables' => array(
'account' => NULL,
),
),
);
}
function user_page_build(&$page) {
$path = drupal_get_path('module', 'user');
$page['#attached']['css'][$path . '/css/user.module.css'] = array(
'every_page' => TRUE,
);
}
function user_entity_bundle_info() {
$bundles['user']['user']['label'] = t('User');
return $bundles;
}
function user_uri($user) {
return array(
'path' => 'user/' . $user
->id(),
);
}
function user_label($entity_type, $entity) {
return user_format_name($entity
->getBCEntity());
}
function user_attach_accounts(array $entities) {
$uids = array();
foreach ($entities as $entity) {
$uids[] = $entity->uid;
}
$uids = array_unique($uids);
$accounts = user_load_multiple($uids);
$anonymous = drupal_anonymous_user();
foreach ($entities as $id => $entity) {
if (isset($accounts[$entity->uid])) {
$entities[$id]->account = $accounts[$entity->uid];
}
else {
$entities[$id]->account = $anonymous;
}
}
}
function user_picture_enabled() {
return (bool) field_info_instance('user', 'user_picture', 'user');
}
function user_field_info_alter(&$info) {
foreach ($info as $field_type => &$field_type_info) {
$field_type_info += array(
'instance_settings' => array(),
);
$field_type_info['instance_settings'] += array(
'user_register_form' => FALSE,
);
}
}
function user_field_extra_fields() {
$fields['user']['user']['form']['account'] = array(
'label' => t('User name and password'),
'description' => t('User module account form elements.'),
'weight' => -10,
);
if (config('user.settings')
->get('signatures')) {
$fields['user']['user']['form']['signature_settings'] = array(
'label' => t('Signature settings'),
'description' => t('User module form element.'),
'weight' => 1,
);
}
$fields['user']['user']['form']['language'] = array(
'label' => t('Language settings'),
'description' => t('User module form element.'),
'weight' => 0,
);
if (config('system.timezone')
->get('user.configurable')) {
$fields['user']['user']['form']['timezone'] = array(
'label' => t('Timezone'),
'description' => t('System module form element.'),
'weight' => 6,
);
}
$fields['user']['user']['display']['member_for'] = array(
'label' => t('Member for'),
'description' => t('User module \'member for\' view element.'),
'weight' => 5,
);
return $fields;
}
function user_load_multiple(array $uids = NULL, $reset = FALSE) {
$entities = entity_load_multiple('user', $uids, $reset);
foreach ($entities as $id => $entity) {
$entities[$id] = $entity
->getBCEntity();
}
return $entities;
}
function user_load($uid, $reset = FALSE) {
$user = entity_load('user', $uid, $reset);
return $user ? $user
->getBCEntity() : FALSE;
}
function user_load_by_mail($mail) {
$users = entity_load_multiple_by_properties('user', array(
'mail' => $mail,
));
return $users ? reset($users)
->getBCEntity() : FALSE;
}
function user_load_by_name($name) {
$users = entity_load_multiple_by_properties('user', array(
'name' => $name,
));
return $users ? reset($users)
->getBCEntity() : FALSE;
}
function user_validate_name($name) {
if (!$name) {
return t('You must enter a username.');
}
if (substr($name, 0, 1) == ' ') {
return t('The username cannot begin with a space.');
}
if (substr($name, -1) == ' ') {
return t('The username cannot end with a space.');
}
if (strpos($name, ' ') !== FALSE) {
return t('The username cannot contain multiple spaces in a row.');
}
if (preg_match('/[^\\x{80}-\\x{F7} a-z0-9@_.\'-]/i', $name)) {
return t('The username contains an illegal character.');
}
if (preg_match('/[\\x{80}-\\x{A0}' . '\\x{AD}' . '\\x{2000}-\\x{200F}' . '\\x{2028}-\\x{202F}' . '\\x{205F}-\\x{206F}' . '\\x{FEFF}' . '\\x{FF01}-\\x{FF60}' . '\\x{FFF9}-\\x{FFFD}' . '\\x{0}-\\x{1F}]/u', $name)) {
return t('The username contains an illegal character.');
}
if (drupal_strlen($name) > USERNAME_MAX_LENGTH) {
return t('The username %name is too long: it must be %max characters or less.', array(
'%name' => $name,
'%max' => USERNAME_MAX_LENGTH,
));
}
}
function user_password($length = 10) {
$allowable_characters = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789';
$len = strlen($allowable_characters) - 1;
$pass = '';
for ($i = 0; $i < $length; $i++) {
$pass .= $allowable_characters[mt_rand(0, $len)];
}
return $pass;
}
function user_role_permissions($roles) {
$cache =& drupal_static(__FUNCTION__, array());
$role_permissions = $fetch = array();
foreach ($roles as $rid) {
if (isset($cache[$rid])) {
$role_permissions[$rid] = $cache[$rid];
}
else {
$fetch[] = $rid;
$cache[$rid] = array();
}
}
if ($fetch) {
$result = db_query("SELECT rid, permission FROM {role_permission} WHERE rid IN (:fetch)", array(
':fetch' => $fetch,
));
foreach ($result as $row) {
$cache[$row->rid][$row->permission] = TRUE;
}
foreach ($fetch as $rid) {
$role_permissions[$rid] = $cache[$rid];
}
}
return $role_permissions;
}
function user_access($string, AccountInterface $account = NULL) {
global $user;
if (!isset($account)) {
$account = $user;
}
$account = $account instanceof User ? $account
->getBCEntity() : $account;
if ($account->uid == 1) {
return TRUE;
}
static $drupal_static_fast;
if (!isset($drupal_static_fast)) {
$drupal_static_fast['perm'] =& drupal_static(__FUNCTION__);
}
$perm =& $drupal_static_fast['perm'];
if (!isset($perm[$account->uid])) {
$role_permissions = user_role_permissions($account
->getRoles());
$perms = array();
foreach ($role_permissions as $one_role) {
$perms += $one_role;
}
$perm[$account->uid] = $perms;
}
return isset($perm[$account->uid][$string]);
}
function user_is_blocked($name) {
return db_select('users')
->fields('users', array(
'name',
))
->condition('name', db_like($name), 'LIKE')
->condition('status', 0)
->execute()
->fetchObject();
}
function user_permission() {
return array(
'administer permissions' => array(
'title' => t('Administer permissions'),
'restrict access' => TRUE,
),
'administer users' => array(
'title' => t('Administer users'),
'restrict access' => TRUE,
),
'access user profiles' => array(
'title' => t('View user profiles'),
),
'change own username' => array(
'title' => t('Change own username'),
),
'cancel account' => array(
'title' => t('Cancel own user account'),
'description' => t('Note: content may be kept, unpublished, deleted or transferred to the %anonymous-name user depending on the configured <a href="@user-settings-url">user settings</a>.', array(
'%anonymous-name' => config('user.settings')
->get('anonymous'),
'@user-settings-url' => url('admin/config/people/accounts'),
)),
),
'select account cancellation method' => array(
'title' => t('Select method for cancelling own account'),
'restrict access' => TRUE,
),
);
}
function user_search_info() {
return array(
'title' => 'Users',
);
}
function user_search_access() {
return user_access('access user profiles');
}
function user_search_execute($keys = NULL, $conditions = NULL) {
$find = array();
$keys = preg_replace('!\\*+!', '%', $keys);
$query = db_select('users')
->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender');
$query
->fields('users', array(
'uid',
));
if (user_access('administer users')) {
$query
->fields('users', array(
'mail',
));
$query
->condition(db_or()
->condition('name', '%' . db_like($keys) . '%', 'LIKE')
->condition('mail', '%' . db_like($keys) . '%', 'LIKE'));
}
else {
$query
->condition('name', '%' . db_like($keys) . '%', 'LIKE')
->condition('status', 1);
}
$uids = $query
->limit(15)
->execute()
->fetchCol();
$accounts = user_load_multiple($uids);
$results = array();
foreach ($accounts as $account) {
$result = array(
'title' => user_format_name($account),
'link' => url('user/' . $account->uid, array(
'absolute' => TRUE,
)),
);
if (user_access('administer users')) {
$result['title'] .= ' (' . $account->mail . ')';
}
$results[] = $result;
}
return $results;
}
function user_user_view(UserInterface $account, EntityDisplay $display) {
if ($display
->getComponent('member_for')) {
$account->content['member_for'] = array(
'#type' => 'item',
'#title' => t('Member for'),
'#markup' => format_interval(REQUEST_TIME - $account->created),
);
}
}
function _user_language_selector_langcode_value($element, $input, &$form_state) {
if (isset($form_state['complete_form']['language']['preferred_langcode']['#description'])) {
$form_state['complete_form']['language']['preferred_langcode']['#description'] .= ' ' . t("This is also assumed to be the primary language of this account's profile information.");
}
return $form_state['values']['preferred_langcode'];
}
function user_validate_current_pass(&$form, &$form_state) {
$account = $form_state['user'];
foreach ($form_state['values']['current_pass_required_values'] as $key => $name) {
if (strlen(trim($form_state['values'][$key])) > 0 && $form_state['values'][$key] != $account->{$key}) {
$current_pass_failed = empty($form_state['values']['current_pass']) || !drupal_container()
->get('password')
->check($form_state['values']['current_pass'], $account);
if ($current_pass_failed) {
form_set_error('current_pass', t("Your current password is missing or incorrect; it's required to change the %name.", array(
'%name' => $name,
)));
form_set_error($key);
}
break;
}
}
}
function user_preprocess_block(&$variables) {
if ($variables['configuration']['module'] == 'user') {
switch ($variables['elements']['#plugin_id']) {
case 'user_login_block':
$variables['attributes']['role'] = 'form';
break;
case 'user_new_block':
$variables['attributes']['role'] = 'complementary';
break;
case 'user_online_block':
$variables['attributes']['role'] = 'complementary';
break;
}
}
}
function user_format_name($account) {
$name = !empty($account->name) ? $account->name : config('user.settings')
->get('anonymous');
drupal_alter('user_format_name', $name, $account);
return $name;
}
function user_template_preprocess_default_variables_alter(&$variables) {
global $user;
if (!is_object($user)) {
return;
}
$variables['user'] = clone $user;
unset($variables['user']->pass, $variables['user']->sid, $variables['user']->ssid);
$variables['is_admin'] = user_access('access administration pages');
$variables['logged_in'] = $user->uid > 0;
}
function template_preprocess_username(&$variables) {
$account = $variables['account'];
if ($account instanceof User) {
$account = $account
->getBCEntity();
}
$variables['extra'] = '';
$variables['attributes'] = array();
if (empty($account->uid)) {
$variables['uid'] = 0;
if (theme_get_setting('features.comment_user_verification')) {
$variables['extra'] = ' (' . t('not verified') . ')';
}
}
else {
$variables['uid'] = (int) $account->uid;
}
$name = $variables['name_raw'] = user_format_name($account);
if (drupal_strlen($name) > 20) {
$name = drupal_substr($name, 0, 15) . '...';
}
$variables['name'] = check_plain($name);
$variables['profile_access'] = user_access('access user profiles');
if ($variables['uid'] && $variables['profile_access']) {
$variables['link_options']['attributes']['title'] = t('View user profile.');
$variables['link_path'] = 'user/' . $variables['uid'];
}
elseif (!empty($account->homepage)) {
$variables['link_options']['attributes']['rel'] = 'nofollow';
$variables['link_path'] = $account->homepage;
$variables['homepage'] = $account->homepage;
}
$variables['link_options']['html'] = TRUE;
$variables['link_options']['attributes']['class'] = array(
'username',
);
}
function theme_username($variables) {
if (isset($variables['link_path'])) {
$output = l($variables['name'] . $variables['extra'], $variables['link_path'], $variables['link_options']);
}
else {
$output = '<span' . new Attribute($variables['attributes']) . '>' . $variables['name'] . $variables['extra'] . '</span>';
}
return $output;
}
function user_is_anonymous() {
return !$GLOBALS['user']->uid || !empty($GLOBALS['menu_admin']);
}
function user_is_logged_in() {
return (bool) $GLOBALS['user']->uid;
}
function user_register_access() {
return user_is_anonymous() && config('user.settings')
->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY;
}
function user_menu() {
$items['user'] = array(
'title' => 'User account',
'title callback' => 'user_menu_title',
'page callback' => 'user_page',
'access callback' => TRUE,
'file' => 'user.pages.inc',
'weight' => -10,
'menu_name' => 'account',
);
$items['user/login'] = array(
'title' => 'Log in',
'access callback' => 'user_is_anonymous',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['user/login/default'] = array(
'title' => 'Username and password',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['user/register'] = array(
'title' => 'Create new account',
'type' => MENU_LOCAL_TASK,
'route_name' => 'user_register',
);
$items['user/password'] = array(
'title' => 'Request new password',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'user_pass',
),
'access callback' => TRUE,
'type' => MENU_LOCAL_TASK,
'file' => 'user.pages.inc',
);
$items['user/reset/%/%/%'] = array(
'title' => 'Reset password',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'user_pass_reset',
2,
3,
4,
),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
'file' => 'user.pages.inc',
);
$items['user/logout'] = array(
'title' => 'Log out',
'route_name' => 'user_logout',
'weight' => 10,
'menu_name' => 'account',
);
$items['admin/people'] = array(
'title' => 'People',
'description' => 'Manage user accounts, roles, and permissions.',
'page callback' => 'user_admin_account',
'access arguments' => array(
'administer users',
),
'position' => 'left',
'weight' => -4,
'file' => 'user.admin.inc',
);
$items['admin/people/permissions'] = array(
'title' => 'Permissions',
'description' => 'Determine access to features by selecting permissions for roles.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'user_admin_permissions',
),
'access arguments' => array(
'administer permissions',
),
'file' => 'user.admin.inc',
'type' => MENU_LOCAL_TASK,
);
$items['admin/people/roles'] = array(
'title' => 'Roles',
'description' => 'List, edit, or add user roles.',
'route_name' => 'user_role_list',
'type' => MENU_LOCAL_TASK,
);
$items['admin/people/roles/add'] = array(
'title' => 'Add role',
'route_name' => 'user_role_add',
'type' => MENU_LOCAL_ACTION,
);
$items['admin/people/roles/manage/%user_role'] = array(
'title' => 'Edit role',
'route_name' => 'user_role_edit',
);
$items['admin/people/roles/manage/%user_role/edit'] = array(
'title' => 'Edit',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/people/roles/manage/%user_role/delete'] = array(
'title' => 'Delete role',
'route_name' => 'user_role_delete',
'weight' => 10,
'context' => MENU_CONTEXT_INLINE,
);
$items['admin/people/create'] = array(
'title' => 'Add user',
'route_name' => 'user_admin_create',
'type' => MENU_LOCAL_ACTION,
);
$items['admin/people/cancel'] = array(
'title' => 'Cancel user',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'user_multiple_cancel_confirm',
),
'access arguments' => array(
'administer users',
),
'file' => 'user.admin.inc',
'type' => MENU_CALLBACK,
);
$items['admin/config/people'] = array(
'title' => 'People',
'description' => 'Configure user accounts.',
'position' => 'left',
'weight' => -20,
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array(
'access administration pages',
),
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
);
$items['admin/config/people/accounts'] = array(
'title' => 'Account settings',
'description' => 'Configure default behavior of users, including registration requirements, e-mails, and fields.',
'weight' => -10,
'route_name' => 'user_account_settings',
);
$items['admin/config/people/accounts/settings'] = array(
'title' => 'Settings',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['user/%user'] = array(
'title' => 'My account',
'title callback' => 'user_page_title',
'title arguments' => array(
1,
),
'page callback' => 'user_view_page',
'page arguments' => array(
1,
),
'access callback' => 'entity_page_access',
'access arguments' => array(
1,
),
);
$items['user/%user/view'] = array(
'title' => 'View',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['user/%user/cancel'] = array(
'title' => 'Cancel account',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'user_cancel_confirm_form',
1,
),
'access callback' => 'entity_page_access',
'access arguments' => array(
1,
'delete',
),
'file' => 'user.pages.inc',
);
$items['user/%user/cancel/confirm/%/%'] = array(
'title' => 'Confirm account cancellation',
'page callback' => 'user_cancel_confirm',
'page arguments' => array(
1,
4,
5,
),
'access callback' => 'entity_page_access',
'access arguments' => array(
1,
'delete',
),
'file' => 'user.pages.inc',
);
$items['user/%user/edit'] = array(
'title' => 'Edit',
'page callback' => 'entity_get_form',
'page arguments' => array(
1,
'profile',
),
'access callback' => 'entity_page_access',
'access arguments' => array(
1,
'update',
),
'type' => MENU_LOCAL_TASK,
'file' => 'user.pages.inc',
);
return $items;
}
function user_menu_link_presave(MenuLink $menu_link) {
if ($menu_link->link_path == 'user' && $menu_link->module == 'system') {
$menu_link->options['alter'] = TRUE;
}
if ($menu_link->link_path == 'user/logout' && $menu_link->module == 'system' && empty($menu_link->customized)) {
$menu_link->plid = 0;
}
}
function user_menu_breadcrumb_alter(&$active_trail, $item) {
if (isset($active_trail[1]['module']) && $active_trail[1]['module'] == 'system' && $active_trail[1]['link_path'] == 'user' && strpos($item['path'], 'user/%') === 0) {
array_splice($active_trail, 1, 1);
}
}
function user_menu_link_load($menu_links) {
foreach ($menu_links as $link) {
if ($link['link_path'] == 'user' && $link['module'] == 'system' && !$GLOBALS['user']->uid) {
$link['hidden'] = 1;
}
}
}
function user_admin_paths() {
$paths = array(
'user/*/cancel' => TRUE,
'user/*/edit' => TRUE,
'user/*/edit/*' => TRUE,
'user/*/translations' => TRUE,
'user/*/translations/*' => TRUE,
);
return $paths;
}
function user_uid_only_optional_to_arg($arg) {
return user_uid_optional_to_arg($arg);
}
function user_uid_optional_load($uid = NULL) {
if (!isset($uid)) {
$uid = $GLOBALS['user']->uid;
}
return user_load($uid);
}
function user_uid_optional_to_arg($arg) {
return empty($arg) || $arg == '%' ? $GLOBALS['user']->uid : $arg;
}
function user_menu_title() {
if (!user_is_logged_in()) {
switch (current_path()) {
case 'user':
case 'user/login':
return t('Log in');
case 'user/register':
return t('Create new account');
case 'user/password':
return t('Request new password');
default:
return t('User account');
}
}
else {
return t('My account');
}
}
function user_page_title($account) {
return is_object($account) ? user_format_name($account) : '';
}
function user_login_form($form, &$form_state) {
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Username'),
'#size' => 60,
'#maxlength' => USERNAME_MAX_LENGTH,
'#description' => t('Enter your @s username.', array(
'@s' => config('system.site')
->get('name'),
)),
'#required' => TRUE,
'#attributes' => array(
'autocorrect' => 'off',
'autocapitalize' => 'off',
'spellcheck' => 'false',
'autofocus' => 'autofocus',
),
);
$form['pass'] = array(
'#type' => 'password',
'#title' => t('Password'),
'#size' => 60,
'#description' => t('Enter the password that accompanies your username.'),
'#required' => TRUE,
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Log in'),
);
$form['#validate'] = user_login_default_validators();
return $form;
}
function user_login_default_validators() {
return array(
'user_login_name_validate',
'user_login_authenticate_validate',
'user_login_final_validate',
);
}
function user_login_name_validate($form, &$form_state) {
if (!empty($form_state['values']['name']) && user_is_blocked($form_state['values']['name'])) {
form_set_error('name', t('The username %name has not been activated or is blocked.', array(
'%name' => $form_state['values']['name'],
)));
}
}
function user_login_authenticate_validate($form, &$form_state) {
$password = trim($form_state['values']['pass']);
$flood_config = config('user.flood');
$flood = Drupal::service('flood');
if (!empty($form_state['values']['name']) && !empty($password)) {
if (!$flood
->isAllowed('user.failed_login_ip', $flood_config
->get('ip_limit'), $flood_config
->get('ip_window'))) {
$form_state['flood_control_triggered'] = 'ip';
return;
}
$account = db_query("SELECT * FROM {users} WHERE name = :name AND status = 1", array(
':name' => $form_state['values']['name'],
))
->fetchObject();
if ($account) {
if ($flood_config
->get('uid_only')) {
$identifier = $account->uid;
}
else {
$identifier = $account->uid . '-' . Drupal::request()
->getClientIP();
}
$form_state['flood_control_user_identifier'] = $identifier;
if (!$flood
->isAllowed('user.failed_login_user', $flood_config
->get('user_limit'), $flood_config
->get('user_window'), $identifier)) {
$form_state['flood_control_triggered'] = 'user';
return;
}
}
$form_state['uid'] = user_authenticate($form_state['values']['name'], $password);
}
}
function user_login_final_validate($form, &$form_state) {
$flood_config = config('user.flood');
$flood = Drupal::service('flood');
if (empty($form_state['uid'])) {
$flood
->register('user.failed_login_ip', $flood_config
->get('ip_window'));
if (isset($form_state['flood_control_user_identifier'])) {
$flood
->register('user.failed_login_user', $flood_config
->get('user_window'), $form_state['flood_control_user_identifier']);
}
if (isset($form_state['flood_control_triggered'])) {
if ($form_state['flood_control_triggered'] == 'user') {
form_set_error('name', format_plural($flood_config
->get('user_limit'), 'Sorry, there has been more than one failed login attempt for this account. It is temporarily blocked. Try again later or <a href="@url">request a new password</a>.', 'Sorry, there have been more than @count failed login attempts for this account. It is temporarily blocked. Try again later or <a href="@url">request a new password</a>.', array(
'@url' => url('user/password'),
)));
}
else {
form_set_error('name', t('Sorry, too many failed login attempts from your IP address. This IP address is temporarily blocked. Try again later or <a href="@url">request a new password</a>.', array(
'@url' => url('user/password'),
)));
}
}
else {
form_set_error('name', t('Sorry, unrecognized username or password. <a href="@password">Have you forgotten your password?</a>', array(
'@password' => url('user/password', array(
'query' => array(
'name' => $form_state['values']['name'],
),
)),
)));
if (user_load_by_name($form_state['values']['name'])) {
watchdog('user', 'Login attempt failed for %user.', array(
'%user' => $form_state['values']['name'],
));
}
else {
watchdog('user', 'Login attempt failed from %ip.', array(
'%ip' => Drupal::request()
->getClientIp(),
));
}
}
}
elseif (isset($form_state['flood_control_user_identifier'])) {
$flood
->clear('user.failed_login_user', $form_state['flood_control_user_identifier']);
}
}
function user_authenticate($name, $password) {
$uid = FALSE;
if (!empty($name) && !empty($password)) {
$account = user_load_by_name($name);
if ($account) {
$password_hasher = drupal_container()
->get('password');
if ($password_hasher
->check($password, $account)) {
$uid = $account->uid;
if ($password_hasher
->userNeedsNewHash($account)) {
$account->pass = $password;
$account
->save();
}
}
}
}
return $uid;
}
function user_login_finalize(&$edit = array()) {
global $user;
watchdog('user', 'Session opened for %name.', array(
'%name' => $user->name,
));
$user->login = REQUEST_TIME;
db_update('users')
->fields(array(
'login' => $user->login,
))
->condition('uid', $user->uid)
->execute();
drupal_session_regenerate();
module_invoke_all('user_login', $user);
}
function user_login_form_submit($form, &$form_state) {
global $user;
$user = user_load($form_state['uid']);
$form_state['redirect'] = 'user/' . $user->uid;
user_login_finalize($form_state);
}
function user_user_login($account) {
drupal_static_reset('template_preprocess');
}
function user_user_logout($account) {
drupal_static_reset('template_preprocess');
}
function user_pass_reset_url($account, $options = array()) {
$timestamp = REQUEST_TIME;
$langcode = isset($options['langcode']) ? $options['langcode'] : user_preferred_langcode($account);
$url_options = array(
'absolute' => TRUE,
'language' => language_load($langcode),
);
return url("user/reset/{$account->uid}/{$timestamp}/" . user_pass_rehash($account->pass, $timestamp, $account->login), $url_options);
}
function user_cancel_url($account, $options = array()) {
$timestamp = REQUEST_TIME;
$langcode = isset($options['langcode']) ? $options['langcode'] : user_preferred_langcode($account);
$url_options = array(
'absolute' => TRUE,
'language' => language_load($langcode),
);
return url("user/{$account->uid}/cancel/confirm/{$timestamp}/" . user_pass_rehash($account->pass, $timestamp, $account->login), $url_options);
}
function user_pass_rehash($password, $timestamp, $login) {
return Crypt::hmacBase64($timestamp . $login, drupal_get_hash_salt() . $password);
}
function user_cancel($edit, $uid, $method) {
global $user;
$account = user_load($uid);
if (!$account) {
drupal_set_message(t('The user account %id does not exist.', array(
'%id' => $uid,
)), 'error');
watchdog('user', 'Attempted to cancel non-existing user account: %id.', array(
'%id' => $uid,
), WATCHDOG_ERROR);
return;
}
$batch = array(
'title' => t('Cancelling account'),
'operations' => array(),
);
batch_set($batch);
if ($method != 'user_cancel_delete') {
module_invoke_all('user_cancel', $edit, $account, $method);
}
$batch = array(
'title' => t('Cancelling user account'),
'operations' => array(
array(
'_user_cancel',
array(
$edit,
$account,
$method,
),
),
),
);
if ($account->uid == $user->uid) {
$batch['finished'] = '_user_cancel_session_regenerate';
}
batch_set($batch);
}
function _user_cancel($edit, $account, $method) {
global $user;
switch ($method) {
case 'user_cancel_block':
case 'user_cancel_block_unpublish':
default:
if (!empty($edit['user_cancel_notify'])) {
_user_mail_notify('status_blocked', $account);
}
$account->status = 0;
$account
->save();
drupal_set_message(t('%name has been disabled.', array(
'%name' => $account->name,
)));
watchdog('user', 'Blocked user: %name %email.', array(
'%name' => $account->name,
'%email' => '<' . $account->mail . '>',
), WATCHDOG_NOTICE);
break;
case 'user_cancel_reassign':
case 'user_cancel_delete':
if (!empty($edit['user_cancel_notify'])) {
_user_mail_notify('status_canceled', $account);
}
user_delete($account->uid);
drupal_set_message(t('%name has been deleted.', array(
'%name' => $account->name,
)));
watchdog('user', 'Deleted user: %name %email.', array(
'%name' => $account->name,
'%email' => '<' . $account->mail . '>',
), WATCHDOG_NOTICE);
break;
}
if ($account->uid == $user->uid) {
$user = drupal_anonymous_user();
}
cache_invalidate_tags(array(
'content' => TRUE,
));
}
function _user_cancel_session_regenerate() {
drupal_session_regenerate();
}
function user_delete($uid) {
user_delete_multiple(array(
$uid,
));
}
function user_delete_multiple(array $uids) {
entity_delete_multiple('user', $uids);
}
function user_view_page($account) {
if (is_object($account)) {
return user_view($account);
}
throw new NotFoundHttpException();
}
function user_view($account, $view_mode = 'full', $langcode = NULL) {
return entity_view($account, $view_mode, $langcode);
}
function user_view_multiple($accounts, $view_mode = 'full', $langcode = NULL) {
return entity_view($accounts, $view_mode, $langcode);
}
function user_mail($key, &$message, $params) {
$token_service = Drupal::token();
$langcode = $message['langcode'];
$variables = array(
'user' => $params['account'],
);
$user_config_context = config_context_enter('Drupal\\user\\UserConfigContext');
$user_config_context
->setAccount($params['account']);
$mail_config = config('user.mail');
$token_options = array(
'langcode' => $langcode,
'callback' => 'user_mail_tokens',
'sanitize' => FALSE,
'clear' => TRUE,
);
$message['subject'] .= $token_service
->replace($mail_config
->get($key . '.subject'), $variables, $token_options);
$message['body'][] = $token_service
->replace($mail_config
->get($key . '.body'), $variables, $token_options);
config_context_leave();
}
function user_mail_tokens(&$replacements, $data, $options) {
if (isset($data['user'])) {
$replacements['[user:one-time-login-url]'] = user_pass_reset_url($data['user'], $options);
$replacements['[user:cancel-url]'] = user_cancel_url($data['user'], $options);
}
}
function user_role_names($membersonly = FALSE, $permission = NULL) {
return array_map(function ($item) {
return $item
->label();
}, user_roles($membersonly, $permission));
}
function user_user_role_insert(RoleInterface $role) {
if (in_array($role
->id(), array(
DRUPAL_AUTHENTICATED_RID,
DRUPAL_ANONYMOUS_RID,
))) {
return;
}
$action = entity_create('action', array(
'id' => 'user_add_role_action.' . $role
->id(),
'type' => 'user',
'label' => t('Add the @label role to the selected users', array(
'@label' => $role
->label(),
)),
'configuration' => array(
'rid' => $role
->id(),
),
'plugin' => 'user_add_role_action',
));
$action
->save();
$action = entity_create('action', array(
'id' => 'user_remove_role_action.' . $role
->id(),
'type' => 'user',
'label' => t('Remove the @label role from the selected users', array(
'@label' => $role
->label(),
)),
'configuration' => array(
'rid' => $role
->id(),
),
'plugin' => 'user_remove_role_action',
));
$action
->save();
}
function user_user_role_delete(RoleInterface $role) {
if (in_array($role
->id(), array(
DRUPAL_AUTHENTICATED_RID,
DRUPAL_ANONYMOUS_RID,
))) {
return;
}
$actions = entity_load_multiple('action', array(
'user_add_role_action.' . $role
->id(),
'user_remove_role_action.' . $role
->id(),
));
foreach ($actions as $action) {
$action
->delete();
}
}
function user_roles($membersonly = FALSE, $permission = NULL) {
$user_roles =& drupal_static(__FUNCTION__);
if (empty($permission)) {
$cid = $membersonly ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID;
if (isset($user_roles[$cid])) {
return $user_roles[$cid];
}
}
$roles = entity_load_multiple('user_role');
if ($membersonly) {
unset($roles[DRUPAL_ANONYMOUS_RID]);
}
if (!empty($permission)) {
$result = db_select('role_permission', 'p')
->fields('p', array(
'rid',
))
->condition('p.rid', array_keys($roles))
->condition('p.permission', $permission)
->execute()
->fetchCol();
$roles = array_intersect_key($roles, array_flip($result));
}
if (empty($permission)) {
$user_roles[$cid] = $roles;
}
return $roles;
}
function user_role_load($rid) {
return entity_load('user_role', $rid);
}
function user_permission_get_modules() {
$permissions = array();
foreach (module_implements('permission') as $module) {
$perms = module_invoke($module, 'permission');
foreach ($perms as $key => $value) {
$permissions[$key] = $module;
}
}
return $permissions;
}
function user_role_change_permissions($rid, array $permissions = array()) {
$grant = array_filter($permissions);
if (!empty($grant)) {
user_role_grant_permissions($rid, array_keys($grant));
}
$revoke = array_diff_assoc($permissions, $grant);
if (!empty($revoke)) {
user_role_revoke_permissions($rid, array_keys($revoke));
}
}
function user_role_grant_permissions($rid, array $permissions = array()) {
$modules = user_permission_get_modules();
foreach ($permissions as $name) {
db_merge('role_permission')
->key(array(
'rid' => $rid,
'permission' => $name,
))
->fields(array(
'module' => $modules[$name],
))
->execute();
}
drupal_static_reset('user_access');
drupal_static_reset('user_role_permissions');
}
function user_role_revoke_permissions($rid, array $permissions = array()) {
db_delete('role_permission')
->condition('rid', $rid)
->condition('permission', $permissions, 'IN')
->execute();
drupal_static_reset('user_access');
drupal_static_reset('user_role_permissions');
}
function user_multiple_cancel_confirm($form, &$form_state) {
$accounts = Drupal::service('user.tempstore')
->get('user_user_operations_cancel')
->get($GLOBALS['user']->uid);
$form['accounts'] = array(
'#prefix' => '<ul>',
'#suffix' => '</ul>',
'#tree' => TRUE,
);
foreach ($accounts as $account) {
$uid = $account
->id();
if ($uid <= 1) {
continue;
}
$form['accounts'][$uid] = array(
'#type' => 'hidden',
'#value' => $uid,
'#prefix' => '<li>',
'#suffix' => check_plain($account->name->value) . "</li>\n",
);
}
if (isset($accounts[1])) {
$redirect = count($accounts) == 1;
$message = t('The user account %name cannot be cancelled.', array(
'%name' => $accounts[1]->name->value,
));
drupal_set_message($message, $redirect ? 'error' : 'warning');
if ($redirect) {
drupal_goto('admin/people');
}
}
$form['operation'] = array(
'#type' => 'hidden',
'#value' => 'cancel',
);
form_load_include($form_state, 'inc', 'user', 'user.pages');
$form['user_cancel_method'] = array(
'#type' => 'radios',
'#title' => t('When cancelling these accounts'),
);
$form['user_cancel_method'] += user_cancel_methods();
$form['user_cancel_confirm'] = array(
'#type' => 'checkbox',
'#title' => t('Require e-mail confirmation to cancel account.'),
'#default_value' => FALSE,
'#description' => t('When enabled, the user must confirm the account cancellation via e-mail.'),
);
$form['user_cancel_notify'] = array(
'#type' => 'checkbox',
'#title' => t('Notify user when account is canceled.'),
'#default_value' => FALSE,
'#access' => config('user.settings')
->get('notify.status_canceled'),
'#description' => t('When enabled, the user will receive an e-mail notification after the account has been cancelled.'),
);
return confirm_form($form, t('Are you sure you want to cancel these user accounts?'), 'admin/people', t('This action cannot be undone.'), t('Cancel accounts'), t('Cancel'));
}
function user_multiple_cancel_confirm_submit($form, &$form_state) {
global $user;
Drupal::service('user.tempstore')
->get('user_user_operations_cancel')
->delete($user->uid);
if ($form_state['values']['confirm']) {
foreach ($form_state['values']['accounts'] as $uid => $value) {
if ($uid <= 1) {
continue;
}
if ($uid == $user->uid) {
$admin_form_state = $form_state;
unset($admin_form_state['values']['user_cancel_confirm']);
$admin_form_state['values']['_account'] = user_load($user->uid);
user_cancel_confirm_form_submit(array(), $admin_form_state);
}
else {
user_cancel($form_state['values'], $uid, $form_state['values']['user_cancel_method']);
}
}
}
$form_state['redirect'] = 'admin/people';
}
function user_filters() {
$filters = array();
$roles = user_role_names(TRUE);
unset($roles[DRUPAL_AUTHENTICATED_RID]);
if (count($roles)) {
$filters['role'] = array(
'title' => t('role'),
'field' => 'ur.rid',
'options' => array(
'[any]' => t('any'),
) + $roles,
);
}
$options = array();
foreach (module_implements('permission') as $module) {
$function = $module . '_permission';
if ($permissions = $function()) {
asort($permissions);
foreach ($permissions as $permission => $description) {
$options[t('@module module', array(
'@module' => $module,
))][$permission] = t($permission);
}
}
}
ksort($options);
$filters['permission'] = array(
'title' => t('permission'),
'options' => array(
'[any]' => t('any'),
) + $options,
);
$filters['status'] = array(
'title' => t('status'),
'field' => 'u.status',
'options' => array(
'[any]' => t('any'),
1 => t('active'),
0 => t('blocked'),
),
);
return $filters;
}
function user_build_filter_query(SelectInterface $query) {
$filters = user_filters();
foreach (isset($_SESSION['user_overview_filter']) ? $_SESSION['user_overview_filter'] : array() as $filter) {
list($key, $value) = $filter;
if ($key == 'permission') {
$account = entity_create('user', array(
'uid' => 'user_filter',
'roles' => array(
DRUPAL_AUTHENTICATED_RID,
),
));
if (user_access($value, $account)) {
continue;
}
$users_roles_alias = $query
->join('users_roles', 'ur', '%alias.uid = u.uid');
$permission_alias = $query
->join('role_permission', 'p', $users_roles_alias . '.rid = %alias.rid');
$query
->condition($permission_alias . '.permission', $value);
}
elseif ($key == 'role') {
$users_roles_alias = $query
->join('users_roles', 'ur', '%alias.uid = u.uid');
$query
->condition($users_roles_alias . '.rid', $value);
}
else {
$query
->condition($filters[$key]['field'], $value);
}
}
}
function theme_user_signature($variables) {
$signature = $variables['signature'];
$output = '';
if ($signature) {
$output .= '<div class="clear">';
$output .= '<div>—</div>';
$output .= $signature;
$output .= '</div>';
}
return $output;
}
function user_preferred_langcode($account, $type = NULL, $default = NULL) {
$language_list = language_list();
$account = $account
->getBCEntity();
if (isset($type)) {
$preferred_langcode = $account->{'preferred_' . $type . '_langcode'};
}
else {
$preferred_langcode = $account->preferred_langcode;
}
if (!empty($preferred_langcode) && isset($language_list[$preferred_langcode])) {
return $language_list[$preferred_langcode]->langcode;
}
else {
return $default ? $default : language_default()->langcode;
}
}
function _user_mail_notify($op, $account, $langcode = NULL) {
$notify = config('user.settings')
->get('notify.' . $op);
if ($notify || $op != 'status_canceled' && $op != 'status_blocked') {
$params['account'] = $account;
$langcode = $langcode ? $langcode : user_preferred_langcode($account);
$site_mail = config('system.site')
->get('mail_notification');
if (empty($site_mail)) {
$site_mail = config('system.site')
->get('mail');
}
if (empty($site_mail)) {
$site_mail = ini_get('sendmail_from');
}
$mail = drupal_mail('user', $op, $account->mail, $langcode, $params, $site_mail);
if ($op == 'register_pending_approval') {
drupal_mail('user', 'register_pending_approval_admin', $site_mail, language_default()->langcode, $params);
}
}
return empty($mail) ? NULL : $mail['result'];
}
function user_form_process_password_confirm($element) {
$password_settings = array(
'confirmTitle' => t('Passwords match:'),
'confirmSuccess' => t('yes'),
'confirmFailure' => t('no'),
'showStrengthIndicator' => FALSE,
);
if (config('user.settings')
->get('password_strength')) {
global $user;
$password_settings['showStrengthIndicator'] = TRUE;
$password_settings += array(
'strengthTitle' => t('Password strength:'),
'hasWeaknesses' => t('To make your password stronger:'),
'tooShort' => t('Make it at least 6 characters'),
'addLowerCase' => t('Add lowercase letters'),
'addUpperCase' => t('Add uppercase letters'),
'addNumbers' => t('Add numbers'),
'addPunctuation' => t('Add punctuation'),
'sameAsUsername' => t('Make it different from your username'),
'weak' => t('Weak'),
'fair' => t('Fair'),
'good' => t('Good'),
'strong' => t('Strong'),
'username' => isset($user->name) ? $user->name : '',
);
}
$js_settings = array(
'password' => $password_settings,
);
$element['#attached']['library'][] = array(
'user',
'drupal.user',
);
static $already_added = FALSE;
if (!$already_added) {
$already_added = TRUE;
$element['#attached']['js'][] = array(
'data' => $js_settings,
'type' => 'setting',
);
}
return $element;
}
function user_node_load($nodes, $types) {
$uids = array();
foreach ($nodes as $nid => $node) {
$uids[$nid] = $node->uid;
}
$user_names = db_query("SELECT uid, name FROM {users} WHERE uid IN (:uids)", array(
':uids' => $uids,
))
->fetchAllKeyed();
foreach ($uids as $nid => $uid) {
$nodes[$nid]->name = $user_names[$uid];
}
}
function user_form_field_ui_field_instance_edit_form_alter(&$form, &$form_state, $form_id) {
$instance = $form_state['instance'];
if ($instance['entity_type'] == 'user') {
$form['instance']['settings']['user_register_form'] = array(
'#type' => 'checkbox',
'#title' => t('Display on user registration form.'),
'#description' => t("This is compulsory for 'required' fields."),
'#default_value' => $instance['settings']['user_register_form'] || $instance['required'],
'#weight' => $form['instance']['required']['#weight'] + 0.1,
'#states' => array(
'enabled' => array(
'input[name="instance[required]"]' => array(
'checked' => FALSE,
),
),
),
'#attached' => array(
'library' => array(
array(
'user',
'drupal.user',
),
),
),
);
array_unshift($form['#submit'], 'user_form_field_ui_field_instance_edit_form_submit');
}
}
function user_form_field_ui_field_instance_edit_form_submit($form, &$form_state) {
$instance = $form_state['values']['instance'];
if (!empty($instance['required'])) {
form_set_value($form['instance']['settings']['user_register_form'], 1, $form_state);
}
}
function user_modules_installed($modules) {
$rid = config('user.settings')
->get('admin_role');
if ($rid) {
$permissions = array();
foreach ($modules as $module) {
if ($module_permissions = module_invoke($module, 'permission')) {
$permissions = array_merge($permissions, array_keys($module_permissions));
}
}
if (!empty($permissions)) {
user_role_grant_permissions($rid, $permissions);
}
}
}
function user_modules_uninstalled($modules) {
db_delete('role_permission')
->condition('module', $modules, 'IN')
->execute();
drupal_container()
->get('user.data')
->delete($modules);
}
function user_login_destination() {
$destination = drupal_get_destination();
if (preg_match('@^user/login(/.*|)$@', $destination['destination'])) {
$destination['destination'] = 'user';
}
return $destination;
}
function user_cookie_save(array $values) {
foreach ($values as $field => $value) {
setrawcookie('Drupal.visitor.' . $field, rawurlencode($value), REQUEST_TIME + 31536000, '/');
}
}
function user_cookie_delete($cookie_name) {
setrawcookie('Drupal.visitor.' . $cookie_name, '', REQUEST_TIME - 3600, '/');
}
function user_rdf_mapping() {
return array(
array(
'type' => 'user',
'bundle' => RDF_DEFAULT_BUNDLE,
'mapping' => array(
'rdftype' => array(
'sioc:UserAccount',
),
'name' => array(
'predicates' => array(
'foaf:name',
),
),
'homepage' => array(
'predicates' => array(
'foaf:page',
),
'type' => 'rel',
),
),
),
);
}
function user_file_download_access($field, EntityInterface $entity, File $file) {
if ($entity
->entityType() == 'user') {
return $entity
->access('view');
}
}
function user_toolbar() {
global $user;
if ($user->uid) {
$links = array(
'account' => array(
'title' => t('View profile'),
'href' => 'user',
'html' => TRUE,
'attributes' => array(
'title' => t('User account'),
),
),
'account_edit' => array(
'title' => t('Edit profile'),
'href' => 'user/' . $user->uid . '/edit',
'html' => TRUE,
'attributes' => array(
'title' => t('Edit user account'),
),
),
'logout' => array(
'title' => t('Log out'),
'href' => 'user/logout',
),
);
}
else {
$links = array(
'login' => array(
'title' => t('Log in'),
'href' => 'user',
),
);
}
$items['user'] = array(
'#type' => 'toolbar_item',
'tab' => array(
'#type' => 'link',
'#title' => user_format_name($user),
'#href' => 'user',
'#options' => array(
'attributes' => array(
'title' => t('My account'),
'class' => array(
'icon',
'icon-user',
),
),
),
),
'tray' => array(
'#heading' => t('User account actions'),
'user_links' => array(
'#theme' => 'links__toolbar_user',
'#links' => $links,
'#attributes' => array(
'class' => array(
'menu',
),
),
),
),
'#weight' => 100,
);
return $items;
}
function user_library_info() {
$libraries['drupal.user'] = array(
'title' => 'User',
'version' => VERSION,
'js' => array(
drupal_get_path('module', 'user') . '/user.js' => array(),
),
'css' => array(
drupal_get_path('module', 'user') . '/css/user.module.css' => array(),
),
'dependencies' => array(
array(
'system',
'jquery',
),
array(
'system',
'drupal',
),
array(
'system',
'jquery.once',
),
),
);
$libraries['drupal.user.permissions'] = array(
'title' => 'User permissions',
'version' => VERSION,
'js' => array(
drupal_get_path('module', 'user') . '/user.permissions.js' => array(),
),
'dependencies' => array(
array(
'system',
'jquery',
),
array(
'system',
'drupal',
),
array(
'system',
'drupalSettings',
),
),
);
return $libraries;
}
function user_logout() {
global $user;
watchdog('user', 'Session closed for %name.', array(
'%name' => $user->name,
));
Drupal::moduleHandler()
->invokeAll('user_logout', array(
$user,
));
session_destroy();
}