Commit 1b55c4f2 authored by alexpott's avatar alexpott

Issue #2302531 by tim.plunkett: Convert database_test_theme_tablesort to a class.

parent a22e2311
<?php
use Drupal\Component\Utility\String;
use Drupal\Core\Database\Query\AlterableInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
......@@ -181,51 +180,3 @@ function database_test_tablesort_first() {
));
}
/**
* Outputs a form without setting a header sort.
*
* @deprecated \Drupal\database_test\Form\DatabaseTestForm::testTablesortDefaultSort()
*/
function database_test_theme_tablesort($form, &$form_state) {
$header = array(
'username' => array('data' => t('Username'), 'field' => 'u.name'),
'status' => array('data' => t('Status'), 'field' => 'u.status'),
);
$query = db_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);
$uids = $query
->execute()
->fetchCol();
$options = array();
foreach (user_load_multiple($uids) as $account) {
$options[$account->id()] = array(
'title' => array('data' => array('#title' => String::checkPlain($account->getUsername()))),
'username' => String::checkPlain($account->getUsername()),
'status' => $account->isActive() ? t('active') : t('blocked'),
);
}
$form['accounts'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
'#empty' => t('No people available.'),
);
return $form;
}
......@@ -36,6 +36,6 @@ database_test.tablesort_first:
database_test.tablesort_default_sort:
path: '/database_test/tablesort_default_sort'
defaults:
_content: '\Drupal\database_test\Form\DatabaseTestForm::testTablesortDefaultSort'
_form: '\Drupal\database_test\Form\DatabaseTestForm'
requirements:
_access: 'TRUE'
......@@ -7,16 +7,72 @@
namespace Drupal\database_test\Form;
use Drupal\Component\Utility\String;
use Drupal\Core\Form\FormBase;
/**
* Temporary form controller for database_test module.
* Form controller for database_test module.
*/
class DatabaseTestForm {
class DatabaseTestForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'database_test_theme_tablesort';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
$header = array(
'username' => array('data' => t('Username'), 'field' => 'u.name'),
'status' => array('data' => t('Status'), 'field' => 'u.status'),
);
$query = db_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);
$uids = $query
->execute()
->fetchCol();
$options = array();
foreach (user_load_multiple($uids) as $account) {
$options[$account->id()] = array(
'title' => array('data' => array('#title' => String::checkPlain($account->getUsername()))),
'username' => String::checkPlain($account->getUsername()),
'status' => $account->isActive() ? t('active') : t('blocked'),
);
}
$form['accounts'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
'#empty' => t('No people available.'),
);
return $form;
}
/**
* @todo Remove database_test_theme_tablesort().
* {@inheritdoc}
*/
public function testTablesortDefaultSort() {
return \Drupal::formBuilder()->getForm('database_test_theme_tablesort');
public function submitForm(array &$form, array &$form_state) {
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment