Issue #2205101 by larowlan: Weird use of globals for table header in Forum.
parent
9065f499af
commit
671271631a
|
@ -74,7 +74,7 @@ function forum_theme() {
|
|||
return array(
|
||||
'forums' => array(
|
||||
'template' => 'forums',
|
||||
'variables' => array('forums' => array(), 'topics' => array(), 'topics_pager' => array(), 'parents' => NULL, 'term' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL),
|
||||
'variables' => array('forums' => array(), 'topics' => array(), 'topics_pager' => array(), 'parents' => NULL, 'term' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL, 'header' => array()),
|
||||
),
|
||||
'forum_list' => array(
|
||||
'template' => 'forum-list',
|
||||
|
@ -623,7 +623,7 @@ function template_preprocess_forums(&$variables) {
|
|||
}
|
||||
|
||||
if ($variables['term'] && empty($variables['term']->forum_container->value) && !empty($variables['topics'])) {
|
||||
global $forum_topic_list_header;
|
||||
$forum_topic_list_header = $variables['header'];
|
||||
|
||||
$table = array(
|
||||
'#theme' => 'table__forum_topic_list',
|
||||
|
|
|
@ -82,12 +82,15 @@ class ForumController extends ControllerBase {
|
|||
$taxonomy_term->parents = $this->forumManager->getParents($taxonomy_term->id());
|
||||
|
||||
if (empty($taxonomy_term->forum_container->value)) {
|
||||
$topics = $this->forumManager->getTopics($taxonomy_term->id());
|
||||
$build = $this->forumManager->getTopics($taxonomy_term->id());
|
||||
$topics = $build['topics'];
|
||||
$header = $build['header'];
|
||||
}
|
||||
else {
|
||||
$topics = '';
|
||||
$header = array();
|
||||
}
|
||||
return $this->build($taxonomy_term->forums, $taxonomy_term, $topics, $taxonomy_term->parents);
|
||||
return $this->build($taxonomy_term->forums, $taxonomy_term, $topics, $taxonomy_term->parents, $header);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -122,17 +125,20 @@ class ForumController extends ControllerBase {
|
|||
* The topics of this forum.
|
||||
* @param array $parents
|
||||
* The parent forums in relation this forum.
|
||||
* @param array $header
|
||||
* Array of header cells.
|
||||
*
|
||||
* @return array
|
||||
* A render array.
|
||||
*/
|
||||
protected function build($forums, TermInterface $term, $topics = array(), $parents = array()) {
|
||||
protected function build($forums, TermInterface $term, $topics = array(), $parents = array(), $header = array()) {
|
||||
$config = $this->config('forum.settings');
|
||||
$build = array(
|
||||
'#theme' => 'forums',
|
||||
'#forums' => $forums,
|
||||
'#topics' => $topics,
|
||||
'#parents' => $parents,
|
||||
'#header' => $header,
|
||||
'#term' => $term,
|
||||
'#sortby' => $config->get('topics.order'),
|
||||
'#forums_per_page' => $config->get('topics.page_limit'),
|
||||
|
|
|
@ -140,19 +140,18 @@ class ForumManager implements ForumManagerInterface {
|
|||
$forum_per_page = $config->get('topics.page_limit');
|
||||
$sortby = $config->get('topics.order');
|
||||
|
||||
global $forum_topic_list_header;
|
||||
$user = \Drupal::currentUser();
|
||||
|
||||
$forum_topic_list_header = array(
|
||||
$header = array(
|
||||
array('data' => $this->t('Topic'), 'field' => 'f.title'),
|
||||
array('data' => $this->t('Replies'), 'field' => 'f.comment_count'),
|
||||
array('data' => $this->t('Last reply'), 'field' => 'f.last_comment_timestamp'),
|
||||
);
|
||||
|
||||
$order = $this->getTopicOrder($sortby);
|
||||
for ($i = 0; $i < count($forum_topic_list_header); $i++) {
|
||||
if ($forum_topic_list_header[$i]['field'] == $order['field']) {
|
||||
$forum_topic_list_header[$i]['sort'] = $order['sort'];
|
||||
for ($i = 0; $i < count($header); $i++) {
|
||||
if ($header[$i]['field'] == $order['field']) {
|
||||
$header[$i]['sort'] = $order['sort'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,7 +164,7 @@ class ForumManager implements ForumManagerInterface {
|
|||
->addTag('node_access')
|
||||
->addMetaData('base_table', 'forum_index')
|
||||
->orderBy('f.sticky', 'DESC')
|
||||
->orderByHeader($forum_topic_list_header)
|
||||
->orderByHeader($header)
|
||||
->limit($forum_per_page);
|
||||
|
||||
$count_query = $this->connection->select('forum_index', 'f');
|
||||
|
@ -207,7 +206,7 @@ class ForumManager implements ForumManagerInterface {
|
|||
|
||||
$query
|
||||
->orderBy('f.sticky', 'DESC')
|
||||
->orderByHeader($forum_topic_list_header)
|
||||
->orderByHeader($header)
|
||||
->condition('n.nid', $nids)
|
||||
// @todo This should be actually filtering on the desired node language
|
||||
// and just fall back to the default language.
|
||||
|
@ -266,7 +265,7 @@ class ForumManager implements ForumManagerInterface {
|
|||
$topics[$topic->id()] = $topic;
|
||||
}
|
||||
|
||||
return $topics;
|
||||
return array('topics' => $topics, 'header' => $header);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ interface ForumManagerInterface {
|
|||
* Term ID.
|
||||
*
|
||||
* @return array
|
||||
* Array of topics.
|
||||
* Array with keys 'topics' and 'header'.
|
||||
*/
|
||||
public function getTopics($tid);
|
||||
|
||||
|
|
Loading…
Reference in New Issue