diff --git a/src/Controller/ScannerController.php b/src/Controller/ScannerController.php index 9697bc14e825cc6ccb74c960125890e6e77b2ea3..af5f6165d6485316cab2c8c322f5ea691547f47c 100644 --- a/src/Controller/ScannerController.php +++ b/src/Controller/ScannerController.php @@ -8,6 +8,7 @@ use Drupal\Core\Link; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\Database\Connection; +use Symfony\Component\HttpFoundation\RequestStack; /** * Controller for Search and Replace module. @@ -17,7 +18,7 @@ class ScannerController extends ControllerBase { /** * Class constructor. */ - public function __construct(protected DateFormatter $dateFormatter, protected Connection $database) { + public function __construct(protected DateFormatter $dateFormatter, protected Connection $database, protected RequestStack $requestStack) { } /** @@ -29,6 +30,7 @@ class ScannerController extends ControllerBase { // Load the service required to construct this class. $container->get('date.formatter'), $container->get('database'), + $container->get('request_stack') ); } @@ -39,26 +41,30 @@ class ScannerController extends ControllerBase { * A render array (table). */ public function undoListing(): array { - $query = $this->database->query('SELECT * from {scanner} WHERE undone = 0'); + $sort_order = $this->requestStack->getCurrentRequest()->query->get('sort', 'asc'); + $query = $this->database->query("SELECT * from {scanner} WHERE undone = 0 ORDER BY time $sort_order"); $results = $query->fetchAll(); $header = [ - $this->t('Date'), + [ + 'data' => $this->t('Date'), + 'sortable' => TRUE, + 'field' => 'date', + ], $this->t('Searched'), $this->t('Replaced'), $this->t('Count'), $this->t('Operation'), ]; $rows = []; - // Build the rows of the table. foreach ($results as $result) { $undo_link = Link::fromTextAndUrl($this->t('Undo'), Url::fromUri("internal:/admin/content/scanner/undo/$result->undo_id/confirm"))->toString(); - $rows[] = [ - $this->dateFormatter->format($result->time), - $result->searched, - $result->replaced, - $result->count, - $undo_link, + $rows[$result->time] = [ + 'date' => $this->dateFormatter->format($result->time), + 'searched' => $result->searched, + 'replaced' => $result->replaced, + 'count' => $result->count, + 'undo_link' => $undo_link, ]; }