diff --git a/core/modules/system/tests/modules/database_test/database_test.module b/core/modules/system/tests/modules/database_test/database_test.module
index dfb38f7..98e0852 100644
--- a/core/modules/system/tests/modules/database_test/database_test.module
+++ b/core/modules/system/tests/modules/database_test/database_test.module
@@ -213,7 +213,7 @@ function database_test_theme_tablesort($form, &$form_state) {
$query = db_select('users', 'u');
$query->condition('u.uid', 0, '<>');
- user_build_filter_query($query);
+ \Drupal\user\Form\UserAdminAccount::buildFilterQuery($query);
$count_query = clone $query;
$count_query->addExpression('COUNT(u.uid)');
diff --git a/core/modules/user/lib/Drupal/user/Form/UserAdminAccount.php b/core/modules/user/lib/Drupal/user/Form/UserAdminAccount.php
new file mode 100644
index 0000000..651c7b7
--- /dev/null
+++ b/core/modules/user/lib/Drupal/user/Form/UserAdminAccount.php
@@ -0,0 +1,189 @@
+ array('data' => t('Username'), 'field' => 'u.name'),
+ 'status' => array('data' => t('Status'), 'field' => 'u.status', 'class' => array(RESPONSIVE_PRIORITY_LOW)),
+ 'roles' => array('data' => t('Roles'), 'class' => array(RESPONSIVE_PRIORITY_LOW)),
+ 'member_for' => array('data' => t('Member for'), 'field' => 'u.created', 'sort' => 'desc', 'class' => array(RESPONSIVE_PRIORITY_LOW)),
+ 'access' => array('data' => t('Last access'), 'field' => 'u.access', 'class' => array(RESPONSIVE_PRIORITY_LOW)),
+ 'operations' => t('Operations'),
+ );
+
+ $query = db_select('users', 'u');
+ $query->condition('u.uid', 0, '<>');
+ $this->buildFilterQuery($query);
+
+ $count_query = clone $query;
+ $count_query->addExpression('COUNT(u.uid)');
+
+ $query = $query
+ ->extend('Drupal\Core\Database\Query\PagerSelectExtender')
+ ->extend('Drupal\Core\Database\Query\TableSortExtender');
+ $query
+ ->fields('u', array('uid', 'name', 'status', 'created', 'access'))
+ ->limit(50)
+ ->orderByHeader($header)
+ ->setCountQuery($count_query);
+ $result = $query->execute();
+
+ $form['options'] = array(
+ '#type' => 'details',
+ '#title' => t('Update options'),
+ '#attributes' => array('class' => array('container-inline')),
+ );
+ $options = array();
+ foreach (module_invoke_all('user_operations') as $operation => $array) {
+ $options[$operation] = $array['label'];
+ }
+ $form['options']['operation'] = array(
+ '#type' => 'select',
+ '#title' => t('Operation'),
+ '#title_display' => 'invisible',
+ '#options' => $options,
+ '#default_value' => 'unblock',
+ );
+ $options = array();
+ $form['options']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Update'),
+ );
+
+ $destination = drupal_get_destination();
+ $status = array(t('blocked'), t('active'));
+ $roles = array_map('check_plain', user_role_names(TRUE));
+ $accounts = array();
+ foreach ($result as $account) {
+ $account = user_load($account->uid);
+ $users_roles = array();
+ $roles_result = db_query('SELECT rid FROM {users_roles} WHERE uid = :uid', array(':uid' => $account->uid));
+ foreach ($roles_result as $user_role) {
+ $users_roles[] = $roles[$user_role->rid];
+ }
+ asort($users_roles);
+
+ $options[$account->uid] = array(
+ 'username' => theme('username', array('account' => $account)),
+ 'status' => $status[$account->status],
+ 'roles' => theme('item_list', array('items' => $users_roles)),
+ 'member_for' => format_interval(REQUEST_TIME - $account->created),
+ 'access' => $account->access ? t('@time ago', array('@time' => format_interval(REQUEST_TIME - $account->access))) : t('never'),
+ );
+ $links = array();
+ $links['edit'] = array(
+ 'title' => t('Edit'),
+ 'href' => 'user/' . $account->uid . '/edit',
+ 'query' => $destination,
+ );
+ if (module_invoke('translation_entity', 'translate_access', $account)) {
+ $links['translate'] = array(
+ 'title' => t('Translate'),
+ 'href' => 'user/' . $account->uid . '/translations',
+ 'query' => $destination,
+ );
+ }
+ $options[$account->uid]['operations']['data'] = array(
+ '#type' => 'operations',
+ '#links' => $links,
+ );
+ }
+
+ $form['accounts'] = array(
+ '#type' => 'tableselect',
+ '#header' => $header,
+ '#options' => $options,
+ '#empty' => t('No people available.'),
+ );
+ $form['pager'] = array('#markup' => theme('pager'));
+
+ return $form;
+ }
+
+ /**
+ * Implements \Drupal\Core\Form\FormInterface::validateForm().
+ */
+ public function validateForm(array &$form, array &$form_state) {
+ $form_state['values']['accounts'] = array_filter($form_state['values']['accounts']);
+ if (count($form_state['values']['accounts']) == 0) {
+ form_set_error('', t('No users selected.'));
+ }
+ }
+
+ /**
+ * Implements \Drupal\Core\Form\FormInterface::submitForm().
+ */
+ public function submitForm(array &$form, array &$form_state) {
+ $operations = module_invoke_all('user_operations', $form, $form_state);
+ $operation = $operations[$form_state['values']['operation']];
+ // Filter out unchecked accounts.
+ $accounts = array_filter($form_state['values']['accounts']);
+ if ($function = $operation['callback']) {
+ // Add in callback arguments if present.
+ if (isset($operation['callback arguments'])) {
+ $args = array_merge(array($accounts), $operation['callback arguments']);
+ }
+ else {
+ $args = array($accounts);
+ }
+ call_user_func_array($function, $args);
+
+ drupal_set_message(t('The update has been performed.'));
+ }
+ }
+
+ /**
+ * Extends a query object for user administration filters based on session.
+ *
+ * @param $query
+ * Query object that should be filtered.
+ */
+ public static function buildFilterQuery(SelectInterface $query) {
+ $filters = UserFilterForm::getFilters();
+ // Extend Query with filter conditions.
+ foreach (isset($_SESSION['user_overview_filter']) ? $_SESSION['user_overview_filter'] : array() as $filter) {
+ list($key, $value) = $filter;
+ // This checks to see if this permission filter is an enabled permission for
+ // the authenticated role. If so, then all users would be listed, and we can
+ // skip adding it to the filter query.
+ if ($key == 'permission') {
+ $account = entity_create('user', array());
+ $account->uid = 'user_filter';
+ $account->roles = array(DRUPAL_AUTHENTICATED_RID => 1);
+ 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);
+ }
+ }
+ }
+
+}
diff --git a/core/modules/user/lib/Drupal/user/Form/UserFilterForm.php b/core/modules/user/lib/Drupal/user/Form/UserFilterForm.php
new file mode 100644
index 0000000..9ee0d2e
--- /dev/null
+++ b/core/modules/user/lib/Drupal/user/Form/UserFilterForm.php
@@ -0,0 +1,176 @@
+getFilters();
+
+ $i = 0;
+ $form['filters'] = array(
+ '#type' => 'details',
+ '#title' => t('Show only users where'),
+ '#theme' => 'exposed_filters__user',
+ );
+ foreach ($session as $filter) {
+ list($type, $value) = $filter;
+ if ($type == 'permission') {
+ // Merge arrays of module permissions into one.
+ // Slice past the first element '[any]' whose value is not an array.
+ $options = call_user_func_array('array_merge', array_slice($filters[$type]['options'], 1));
+ $value = $options[$value];
+ }
+ else {
+ $value = $filters[$type]['options'][$value];
+ }
+ $t_args = array('%property' => $filters[$type]['title'], '%value' => $value);
+ if ($i++) {
+ $form['filters']['current'][] = array('#markup' => t('and where %property is %value', $t_args));
+ }
+ else {
+ $form['filters']['current'][] = array('#markup' => t('%property is %value', $t_args));
+ }
+ }
+
+ $form['filters']['status'] = array(
+ '#type' => 'container',
+ '#attributes' => array('class' => array('clearfix')),
+ '#prefix' => ($i ? '
' . t('and where') . '
' : ''),
+ );
+ $form['filters']['status']['filters'] = array(
+ '#type' => 'container',
+ '#attributes' => array('class' => array('filters')),
+ );
+ foreach ($filters as $key => $filter) {
+ $form['filters']['status']['filters'][$key] = array(
+ '#type' => 'select',
+ '#options' => $filter['options'],
+ '#title' => $filter['title'],
+ '#default_value' => '[any]',
+ );
+ }
+
+ $form['filters']['status']['actions'] = array(
+ '#type' => 'actions',
+ '#attributes' => array('class' => array('container-inline')),
+ );
+ $form['filters']['status']['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => (count($session) ? t('Refine') : t('Filter')),
+ );
+ if (count($session)) {
+ $form['filters']['status']['actions']['undo'] = array(
+ '#type' => 'submit',
+ '#value' => t('Undo'),
+ );
+ $form['filters']['status']['actions']['reset'] = array(
+ '#type' => 'submit',
+ '#value' => t('Reset'),
+ );
+ }
+
+ drupal_add_library('system', 'drupal.form');
+
+ return $form;
+ }
+
+ /**
+ * Implements \Drupal\Core\Form\FormInterface::validateForm().
+ */
+ public function validateForm(array &$form, array &$form_state) {}
+
+ /**
+ * Implements \Drupal\Core\Form\FormInterface::submitForm().
+ */
+ public function submitForm(array &$form, array &$form_state) {
+ $op = $form_state['values']['op'];
+ $filters = $this->getFilters();
+ switch ($op) {
+ case t('Filter'):
+ case t('Refine'):
+ // Apply every filter that has a choice selected other than 'any'.
+ foreach ($filters as $filter => $options) {
+ if (isset($form_state['values'][$filter]) && $form_state['values'][$filter] != '[any]') {
+ $_SESSION['user_overview_filter'][] = array($filter, $form_state['values'][$filter]);
+ }
+ }
+ break;
+ case t('Undo'):
+ array_pop($_SESSION['user_overview_filter']);
+ break;
+ case t('Reset'):
+ $_SESSION['user_overview_filter'] = array();
+ break;
+ case t('Update'):
+ return;
+ }
+
+ $form_state['redirect'] = 'admin/people';
+ return;
+ }
+
+ /**
+ * List user administration filters that can be applied.
+ */
+ public static function getFilters() {
+ // Regular filters
+ $filters = array();
+ $roles = user_role_names(TRUE);
+ unset($roles[DRUPAL_AUTHENTICATED_RID]); // Don't list authorized role.
+ 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;
+ }
+
+}
diff --git a/core/modules/user/lib/Drupal/user/Form/UserMultipleCancelConfirm.php b/core/modules/user/lib/Drupal/user/Form/UserMultipleCancelConfirm.php
new file mode 100644
index 0000000..a86b08e
--- /dev/null
+++ b/core/modules/user/lib/Drupal/user/Form/UserMultipleCancelConfirm.php
@@ -0,0 +1,115 @@
+ '', '#tree' => TRUE);
+ $accounts = user_load_multiple(array_keys(array_filter($edit['accounts'])));
+ foreach ($accounts as $uid => $account) {
+ // Prevent user 1 from being canceled.
+ if ($uid <= 1) {
+ continue;
+ }
+ $form['accounts'][$uid] = array(
+ '#type' => 'hidden',
+ '#value' => $uid,
+ '#prefix' => '',
+ '#suffix' => check_plain($account->name) . "\n",
+ );
+ }
+
+ // Output a notice that user 1 cannot be canceled.
+ if (isset($accounts[1])) {
+ $redirect = (count($accounts) == 1);
+ $message = t('The user account %name cannot be cancelled.', array('%name' => $accounts[1]->name));
+ drupal_set_message($message, $redirect ? 'error' : 'warning');
+ // If only user 1 was selected, redirect to the overview.
+ 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();
+
+ // Allow to send the account cancellation confirmation mail.
+ $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.'),
+ );
+ // Also allow to send account canceled notification mail, if enabled.
+ $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'));
+ }
+
+ /**
+ * Implements \Drupal\Core\Form\FormInterface::validateForm().
+ */
+ public function validateForm(array &$form, array &$form_state) {}
+
+ /**
+ * Implements \Drupal\Core\Form\FormInterface::submitForm().
+ */
+ public function submitForm(array &$form, array &$form_state) {
+ global $user;
+
+ if ($form_state['values']['confirm']) {
+ foreach ($form_state['values']['accounts'] as $uid => $value) {
+ // Prevent programmatic form submissions from cancelling user 1.
+ if ($uid <= 1) {
+ continue;
+ }
+ // Prevent user administrators from deleting themselves without confirmation.
+ if ($uid == $user->uid) {
+ $admin_form_state = $form_state;
+ unset($admin_form_state['values']['user_cancel_confirm']);
+ // The $user global is not a complete user entity, so load the full
+ // entity.
+ $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';
+ }
+
+}
diff --git a/core/modules/user/lib/Drupal/user/UserRouteController.php b/core/modules/user/lib/Drupal/user/UserRouteController.php
index cf3b50e..56313ee 100644
--- a/core/modules/user/lib/Drupal/user/UserRouteController.php
+++ b/core/modules/user/lib/Drupal/user/UserRouteController.php
@@ -25,4 +25,24 @@ public function register() {
return entity_get_form($account, 'register');
}
+ /**
+ * Returns the user listing page.
+ *
+ * @return array
+ * A renderable array containing the administrative list of users.
+ */
+ public function user_list() {
+ // We may have gotten here after selecting one or more user accounts to be
+ // cancelled. If so, display a cancellation confirmation instead of the
+ // usual user list.
+ if (!empty($_POST['accounts']) && isset($_POST['operation']) && ($_POST['operation'] == 'cancel')) {
+ $build['user_multiple_cancel_confirm'] = drupal_get_form(new Form\UserMultipleCancelConfirm());
+ }
+ else {
+ $build['user_filter_form'] = drupal_get_form(new Form\UserFilterForm());
+ $build['user_admin_account'] = drupal_get_form(new Form\UserAdminAccount());
+ }
+ return $build;
+ }
+
}
diff --git a/core/modules/user/user.admin.inc b/core/modules/user/user.admin.inc
index c3931d8..43f7ed6 100644
--- a/core/modules/user/user.admin.inc
+++ b/core/modules/user/user.admin.inc
@@ -6,286 +6,6 @@
*/
/**
- * Page callback: Generates the appropriate user administration form.
- *
- * This function generates the user registration, multiple user cancellation,
- * or filtered user list admin form, depending on the argument and the POST
- * form values.
- *
- * @param string $callback_arg
- * (optional) Indicates which form to build. Defaults to '', which will
- * trigger the user filter form. If the POST value 'op' is present, this
- * function uses that value as the callback argument.
- *
- * @return string
- * A renderable form array for the respective request.
- */
-function user_admin($callback_arg = '') {
- $op = isset($_POST['op']) ? $_POST['op'] : $callback_arg;
-
- switch ($op) {
- case t('Create new account'):
- case 'create':
- $account = entity_create('user', array());
- $build['user_register'] = entity_get_form($account, 'register');
- break;
- default:
- if (!empty($_POST['accounts']) && isset($_POST['operation']) && ($_POST['operation'] == 'cancel')) {
- $build['user_multiple_cancel_confirm'] = drupal_get_form('user_multiple_cancel_confirm');
- }
- else {
- $build['user_filter_form'] = drupal_get_form('user_filter_form');
- $build['user_admin_account'] = drupal_get_form('user_admin_account');
- }
- }
- return $build;
-}
-
-/**
- * Form builder; Return form for user administration filters.
- *
- * @ingroup forms
- * @see user_filter_form_submit()
- */
-function user_filter_form() {
- $session = isset($_SESSION['user_overview_filter']) ? $_SESSION['user_overview_filter'] : array();
- $filters = user_filters();
-
- $i = 0;
- $form['filters'] = array(
- '#type' => 'details',
- '#title' => t('Show only users where'),
- '#theme' => 'exposed_filters__user',
- );
- foreach ($session as $filter) {
- list($type, $value) = $filter;
- if ($type == 'permission') {
- // Merge arrays of module permissions into one.
- // Slice past the first element '[any]' whose value is not an array.
- $options = call_user_func_array('array_merge', array_slice($filters[$type]['options'], 1));
- $value = $options[$value];
- }
- else {
- $value = $filters[$type]['options'][$value];
- }
- $t_args = array('%property' => $filters[$type]['title'], '%value' => $value);
- if ($i++) {
- $form['filters']['current'][] = array('#markup' => t('and where %property is %value', $t_args));
- }
- else {
- $form['filters']['current'][] = array('#markup' => t('%property is %value', $t_args));
- }
- }
-
- $form['filters']['status'] = array(
- '#type' => 'container',
- '#attributes' => array('class' => array('clearfix')),
- '#prefix' => ($i ? '' . t('and where') . '
' : ''),
- );
- $form['filters']['status']['filters'] = array(
- '#type' => 'container',
- '#attributes' => array('class' => array('filters')),
- );
- foreach ($filters as $key => $filter) {
- $form['filters']['status']['filters'][$key] = array(
- '#type' => 'select',
- '#options' => $filter['options'],
- '#title' => $filter['title'],
- '#default_value' => '[any]',
- );
- }
-
- $form['filters']['status']['actions'] = array(
- '#type' => 'actions',
- '#attributes' => array('class' => array('container-inline')),
- );
- $form['filters']['status']['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => (count($session) ? t('Refine') : t('Filter')),
- );
- if (count($session)) {
- $form['filters']['status']['actions']['undo'] = array(
- '#type' => 'submit',
- '#value' => t('Undo'),
- );
- $form['filters']['status']['actions']['reset'] = array(
- '#type' => 'submit',
- '#value' => t('Reset'),
- );
- }
-
- drupal_add_library('system', 'drupal.form');
-
- return $form;
-}
-
-/**
- * Process result from user administration filter form.
- */
-function user_filter_form_submit($form, &$form_state) {
- $op = $form_state['values']['op'];
- $filters = user_filters();
- switch ($op) {
- case t('Filter'):
- case t('Refine'):
- // Apply every filter that has a choice selected other than 'any'.
- foreach ($filters as $filter => $options) {
- if (isset($form_state['values'][$filter]) && $form_state['values'][$filter] != '[any]') {
- $_SESSION['user_overview_filter'][] = array($filter, $form_state['values'][$filter]);
- }
- }
- break;
- case t('Undo'):
- array_pop($_SESSION['user_overview_filter']);
- break;
- case t('Reset'):
- $_SESSION['user_overview_filter'] = array();
- break;
- case t('Update'):
- return;
- }
-
- $form_state['redirect'] = 'admin/people';
- return;
-}
-
-/**
- * Form builder; User administration page.
- *
- * @ingroup forms
- * @see user_admin_account_validate()
- * @see user_admin_account_submit()
- */
-function user_admin_account() {
-
- $header = array(
- 'username' => array('data' => t('Username'), 'field' => 'u.name'),
- 'status' => array('data' => t('Status'), 'field' => 'u.status', 'class' => array(RESPONSIVE_PRIORITY_LOW)),
- 'roles' => array('data' => t('Roles'), 'class' => array(RESPONSIVE_PRIORITY_LOW)),
- 'member_for' => array('data' => t('Member for'), 'field' => 'u.created', 'sort' => 'desc', 'class' => array(RESPONSIVE_PRIORITY_LOW)),
- 'access' => array('data' => t('Last access'), 'field' => 'u.access', 'class' => array(RESPONSIVE_PRIORITY_LOW)),
- 'operations' => t('Operations'),
- );
-
- $query = db_select('users', 'u');
- $query->condition('u.uid', 0, '<>');
- user_build_filter_query($query);
-
- $count_query = clone $query;
- $count_query->addExpression('COUNT(u.uid)');
-
- $query = $query
- ->extend('Drupal\Core\Database\Query\PagerSelectExtender')
- ->extend('Drupal\Core\Database\Query\TableSortExtender');
- $query
- ->fields('u', array('uid', 'name', 'status', 'created', 'access'))
- ->limit(50)
- ->orderByHeader($header)
- ->setCountQuery($count_query);
- $result = $query->execute();
-
- $form['options'] = array(
- '#type' => 'details',
- '#title' => t('Update options'),
- '#attributes' => array('class' => array('container-inline')),
- );
- $options = array();
- foreach (module_invoke_all('user_operations') as $operation => $array) {
- $options[$operation] = $array['label'];
- }
- $form['options']['operation'] = array(
- '#type' => 'select',
- '#title' => t('Operation'),
- '#title_display' => 'invisible',
- '#options' => $options,
- '#default_value' => 'unblock',
- );
- $options = array();
- $form['options']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Update'),
- );
-
- $destination = drupal_get_destination();
- $status = array(t('blocked'), t('active'));
- $roles = array_map('check_plain', user_role_names(TRUE));
- $accounts = array();
- foreach ($result as $account) {
- $account = user_load($account->uid);
- $users_roles = array();
- $roles_result = db_query('SELECT rid FROM {users_roles} WHERE uid = :uid', array(':uid' => $account->uid));
- foreach ($roles_result as $user_role) {
- $users_roles[] = $roles[$user_role->rid];
- }
- asort($users_roles);
-
- $options[$account->uid] = array(
- 'username' => theme('username', array('account' => $account)),
- 'status' => $status[$account->status],
- 'roles' => theme('item_list', array('items' => $users_roles)),
- 'member_for' => format_interval(REQUEST_TIME - $account->created),
- 'access' => $account->access ? t('@time ago', array('@time' => format_interval(REQUEST_TIME - $account->access))) : t('never'),
- );
- $links = array();
- $links['edit'] = array(
- 'title' => t('Edit'),
- 'href' => 'user/' . $account->uid . '/edit',
- 'query' => $destination,
- );
- if (module_invoke('translation_entity', 'translate_access', $account)) {
- $links['translate'] = array(
- 'title' => t('Translate'),
- 'href' => 'user/' . $account->uid . '/translations',
- 'query' => $destination,
- );
- }
- $options[$account->uid]['operations']['data'] = array(
- '#type' => 'operations',
- '#links' => $links,
- );
- }
-
- $form['accounts'] = array(
- '#type' => 'tableselect',
- '#header' => $header,
- '#options' => $options,
- '#empty' => t('No people available.'),
- );
- $form['pager'] = array('#markup' => theme('pager'));
-
- return $form;
-}
-
-/**
- * Submit the user administration update form.
- */
-function user_admin_account_submit($form, &$form_state) {
- $operations = module_invoke_all('user_operations', $form, $form_state);
- $operation = $operations[$form_state['values']['operation']];
- // Filter out unchecked accounts.
- $accounts = array_filter($form_state['values']['accounts']);
- if ($function = $operation['callback']) {
- // Add in callback arguments if present.
- if (isset($operation['callback arguments'])) {
- $args = array_merge(array($accounts), $operation['callback arguments']);
- }
- else {
- $args = array($accounts);
- }
- call_user_func_array($function, $args);
-
- drupal_set_message(t('The update has been performed.'));
- }
-}
-
-function user_admin_account_validate($form, &$form_state) {
- $form_state['values']['accounts'] = array_filter($form_state['values']['accounts']);
- if (count($form_state['values']['accounts']) == 0) {
- form_set_error('', t('No users selected.'));
- }
-}
-
-/**
* Form builder; Configure user settings for this site.
*
* @ingroup forms
diff --git a/core/modules/user/user.module b/core/modules/user/user.module
index bdf5862..36ab150 100644
--- a/core/modules/user/user.module
+++ b/core/modules/user/user.module
@@ -1,6 +1,5 @@
'People',
'description' => 'Manage user accounts, roles, and permissions.',
- 'page callback' => 'user_admin',
- 'page arguments' => array('list'),
- 'access arguments' => array('administer users'),
+ 'route_name' => 'user_list',
'position' => 'left',
'weight' => -4,
- 'file' => 'user.admin.inc',
);
$items['admin/people/people'] = array(
'title' => 'List',
'description' => 'Find and manage people interacting with your site.',
- 'access arguments' => array('administer users'),
'type' => MENU_DEFAULT_LOCAL_TASK,
- 'file' => 'user.admin.inc',
);
// Permissions and role forms.
@@ -983,8 +977,7 @@ function user_menu() {
$items['admin/people/create'] = array(
'title' => 'Add user',
- 'page arguments' => array('create'),
- 'access arguments' => array('administer users'),
+ 'route_name' => 'user_create_user',
'type' => MENU_LOCAL_ACTION,
);
@@ -2118,181 +2111,6 @@ function user_multiple_role_edit($accounts, $operation, $rid) {
}
}
-function user_multiple_cancel_confirm($form, &$form_state) {
- $edit = $form_state['input'];
-
- $form['accounts'] = array('#prefix' => '', '#tree' => TRUE);
- $accounts = user_load_multiple(array_keys(array_filter($edit['accounts'])));
- foreach ($accounts as $uid => $account) {
- // Prevent user 1 from being canceled.
- if ($uid <= 1) {
- continue;
- }
- $form['accounts'][$uid] = array(
- '#type' => 'hidden',
- '#value' => $uid,
- '#prefix' => '',
- '#suffix' => check_plain($account->name) . "\n",
- );
- }
-
- // Output a notice that user 1 cannot be canceled.
- if (isset($accounts[1])) {
- $redirect = (count($accounts) == 1);
- $message = t('The user account %name cannot be cancelled.', array('%name' => $accounts[1]->name));
- drupal_set_message($message, $redirect ? 'error' : 'warning');
- // If only user 1 was selected, redirect to the overview.
- 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();
-
- // Allow to send the account cancellation confirmation mail.
- $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.'),
- );
- // Also allow to send account canceled notification mail, if enabled.
- $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'));
-}
-
-/**
- * Submit handler for mass-account cancellation form.
- *
- * @see user_multiple_cancel_confirm()
- * @see user_cancel_confirm_form_submit()
- */
-function user_multiple_cancel_confirm_submit($form, &$form_state) {
- global $user;
-
- if ($form_state['values']['confirm']) {
- foreach ($form_state['values']['accounts'] as $uid => $value) {
- // Prevent programmatic form submissions from cancelling user 1.
- if ($uid <= 1) {
- continue;
- }
- // Prevent user administrators from deleting themselves without confirmation.
- if ($uid == $user->uid) {
- $admin_form_state = $form_state;
- unset($admin_form_state['values']['user_cancel_confirm']);
- // The $user global is not a complete user entity, so load the full
- // entity.
- $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';
-}
-
-/**
- * List user administration filters that can be applied.
- */
-function user_filters() {
- // Regular filters
- $filters = array();
- $roles = user_role_names(TRUE);
- unset($roles[DRUPAL_AUTHENTICATED_RID]); // Don't list authorized role.
- 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;
-}
-
-/**
- * Extends a query object for user administration filters based on session.
- *
- * @param $query
- * Query object that should be filtered.
- */
-function user_build_filter_query(SelectInterface $query) {
- $filters = user_filters();
- // Extend Query with filter conditions.
- foreach (isset($_SESSION['user_overview_filter']) ? $_SESSION['user_overview_filter'] : array() as $filter) {
- list($key, $value) = $filter;
- // This checks to see if this permission filter is an enabled permission for
- // the authenticated role. If so, then all users would be listed, and we can
- // skip adding it to the filter query.
- if ($key == 'permission') {
- $account = entity_create('user', array());
- $account->uid = 'user_filter';
- $account->roles = array(DRUPAL_AUTHENTICATED_RID => 1);
- 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);
- }
- }
-}
-
/**
* Returns HTML for a user signature.
*
diff --git a/core/modules/user/user.routing.yml b/core/modules/user/user.routing.yml
index 34b6059..0a7da73 100644
--- a/core/modules/user/user.routing.yml
+++ b/core/modules/user/user.routing.yml
@@ -5,6 +5,20 @@ user_register:
requirements:
_access_user_register: 'TRUE'
+user_list:
+ pattern: '/admin/people'
+ defaults:
+ _content: '\Drupal\user\UserRouteController::user_list'
+ requirements:
+ _permission: 'administer users'
+
+user_create_user:
+ pattern: '/admin/people/create'
+ defaults:
+ _content: '\Drupal\user\UserRouteController::register'
+ requirements:
+ _permission: 'administer users'
+
user_autocomplete:
pattern: '/user/autocomplete'
defaults: