diff --git a/core/modules/user/lib/Drupal/user/Controller/UserAdmin.php b/core/modules/user/lib/Drupal/user/Controller/UserAdmin.php index ea8b30a..020075c 100644 --- a/core/modules/user/lib/Drupal/user/Controller/UserAdmin.php +++ b/core/modules/user/lib/Drupal/user/Controller/UserAdmin.php @@ -9,12 +9,15 @@ use Drupal\Core\Controller\ControllerInterface; use Drupal\Core\Database\Connection; +use Drupal\Core\Entity\Query\QueryInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\user\UserStorageControllerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides a user administrative listing. + * + * @todo Convert this to a entity list controller once table sort is supported. */ class UserAdmin implements ControllerInterface { @@ -40,7 +43,14 @@ class UserAdmin implements ControllerInterface { protected $storageController; /** - * Constructs a new UserAdmin. + * The entity query. + * + * @var \Drupal\Core\Entity\Query\QueryInterface + */ + protected $query; + + /** + * Constructs a new UserAdmin object. * * @param \Drupal\Core\Database\Connection $connection * The database connection. @@ -48,11 +58,14 @@ class UserAdmin implements ControllerInterface { * The module handler. * @param \Drupal\user\UserStorageControllerInterface $storage_controller * The user storage controller. + * @param \Drupal\Core\Entity\Query\QueryInterface $query + * The entity query. */ - public function __construct(Connection $connection, ModuleHandlerInterface $module_handler, UserStorageControllerInterface $storage_controller) { + public function __construct(Connection $connection, ModuleHandlerInterface $module_handler, UserStorageControllerInterface $storage_controller, QueryInterface $query) { $this->connection = $connection; $this->moduleHandler = $module_handler; $this->storageController = $storage_controller; + $this->query = $query; } /** @@ -62,38 +75,32 @@ public static function create(ContainerInterface $container) { return new static( $container->get('database'), $container->get('module_handler'), - $container->get('plugin.manager.entity')->getStorageController('user') + $container->get('plugin.manager.entity')->getStorageController('user'), + $container->get('entity.query')->get('user') ); } /** * User administrative listing. + * + * @return array + * A render array as expected by drupal_render(). */ public function userList() { $header = array( - 'username' => array('data' => t('Username'), 'field' => 'u.name'), - 'status' => array('data' => t('Status'), 'field' => 'u.status', 'class' => array(RESPONSIVE_PRIORITY_LOW)), + 'username' => array('data' => t('Username'), 'field' => 'name', 'specifier' => 'name'), + 'status' => array('data' => t('Status'), 'field' => 'status', 'specifier' => '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)), + 'member_for' => array('data' => t('Member for'), 'field' => 'created', 'specifier' => 'created', 'sort' => 'desc', 'class' => array(RESPONSIVE_PRIORITY_LOW)), + 'access' => array('data' => t('Last access'), 'field' => 'access', 'specifier' => 'access', 'class' => array(RESPONSIVE_PRIORITY_LOW)), 'operations' => t('Operations'), ); - $query = $this->connection->select('users', 'u'); - $query->condition('u.uid', 0, '<>'); - - $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')) - ->limit(50) - ->orderByHeader($header) - ->setCountQuery($count_query); - $accounts = $this->storageController->load(array_keys($query->execute()->fetchAllAssoc('uid'))); + $this->query->condition('uid', 0, '<>'); + $this->query->pager(50); + $this->query->tableSort($header); + $uids = $this->query->execute(); + $accounts = $this->storageController->load($uids); $destination = drupal_get_destination(); $status = array(t('blocked'), t('active'));