function ForumManager::getTopicOrder

Same name in other branches
  1. 9 core/modules/forum/src/ForumManager.php \Drupal\forum\ForumManager::getTopicOrder()
  2. 8.9.x core/modules/forum/src/ForumManager.php \Drupal\forum\ForumManager::getTopicOrder()
  3. 10 core/modules/forum/src/ForumManager.php \Drupal\forum\ForumManager::getTopicOrder()

Gets topic sorting information based on an integer code.

Parameters

int $sortby: One of the following integers indicating the sort criteria:

Return value

array An array with the following values:

  • field: A field for an SQL query.
  • sort: 'asc' or 'desc'.
1 call to ForumManager::getTopicOrder()
ForumManager::getTopics in core/modules/forum/src/ForumManager.php

File

core/modules/forum/src/ForumManager.php, line 293

Class

ForumManager
Provides forum manager service.

Namespace

Drupal\forum

Code

protected function getTopicOrder($sortby) {
    switch ($sortby) {
        case static::NEWEST_FIRST:
            return [
                'field' => 'f.last_comment_timestamp',
                'sort' => 'desc',
            ];
        case static::OLDEST_FIRST:
            return [
                'field' => 'f.last_comment_timestamp',
                'sort' => 'asc',
            ];
        case static::MOST_POPULAR_FIRST:
            return [
                'field' => 'f.comment_count',
                'sort' => 'desc',
            ];
        case static::LEAST_POPULAR_FIRST:
            return [
                'field' => 'f.comment_count',
                'sort' => 'asc',
            ];
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.