diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index f446c49..60f301c 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -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', @@ -657,7 +657,7 @@ function template_preprocess_forums(&$variables) { } if ($variables['term'] && empty($variables['term']->forum_container->value) && !empty($variables['topics'])) { - $forum_topic_list_header = \Drupal::service('forum.manager')->getHeader(); + $forum_topic_list_header = $variables['header']; $table = array( '#theme' => 'table__forum_topic_list', diff --git a/core/modules/forum/lib/Drupal/forum/Controller/ForumController.php b/core/modules/forum/lib/Drupal/forum/Controller/ForumController.php index e982429..d503cdb 100644 --- a/core/modules/forum/lib/Drupal/forum/Controller/ForumController.php +++ b/core/modules/forum/lib/Drupal/forum/Controller/ForumController.php @@ -82,12 +82,15 @@ public function forumPage(TermInterface $taxonomy_term) { $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 @@ public function forumIndex() { * 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'), diff --git a/core/modules/forum/lib/Drupal/forum/ForumManager.php b/core/modules/forum/lib/Drupal/forum/ForumManager.php index 0805bf8..a5ba96b 100644 --- a/core/modules/forum/lib/Drupal/forum/ForumManager.php +++ b/core/modules/forum/lib/Drupal/forum/ForumManager.php @@ -97,13 +97,6 @@ class ForumManager implements ForumManagerInterface { protected $index; /** - * Cached table header. - * - * @var array - */ - protected $header; - - /** * Field info service. * * @var \Drupal\field\FieldInfo @@ -149,16 +142,16 @@ public function getTopics($tid) { $user = \Drupal::currentUser(); - $this->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($this->header); $i++) { - if ($this->header[$i]['field'] == $order['field']) { - $this->header[$i]['sort'] = $order['sort']; + for ($i = 0; $i < count($header); $i++) { + if ($header[$i]['field'] == $order['field']) { + $header[$i]['sort'] = $order['sort']; } } @@ -171,7 +164,7 @@ public function getTopics($tid) { ->addTag('node_access') ->addMetaData('base_table', 'forum_index') ->orderBy('f.sticky', 'DESC') - ->orderByHeader($this->header) + ->orderByHeader($header) ->limit($forum_per_page); $count_query = $this->connection->select('forum_index', 'f'); @@ -213,7 +206,7 @@ public function getTopics($tid) { $query ->orderBy('f.sticky', 'DESC') - ->orderByHeader($this->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. @@ -272,7 +265,7 @@ public function getTopics($tid) { $topics[$topic->id()] = $topic; } - return $topics; + return array('topics' => $topics, 'header' => $header); } @@ -566,11 +559,4 @@ protected function t($string, array $args = array(), array $options = array()) { return $this->translationManager->translate($string, $args, $options); } - /** - * {@inheritdoc} - */ - public function getHeader() { - return $this->header; - } - } diff --git a/core/modules/forum/lib/Drupal/forum/ForumManagerInterface.php b/core/modules/forum/lib/Drupal/forum/ForumManagerInterface.php index 48cdd3b..cdcfb38 100644 --- a/core/modules/forum/lib/Drupal/forum/ForumManagerInterface.php +++ b/core/modules/forum/lib/Drupal/forum/ForumManagerInterface.php @@ -21,7 +21,7 @@ * Term ID. * * @return array - * Array of topics. + * Array with keys 'topics' and 'header'. */ public function getTopics($tid); @@ -101,12 +101,4 @@ public function unreadTopics($term, $uid); */ public function updateIndex($nid); - /** - * Returns the topic list header. - * - * @return array - * Array representing the table list header. - */ - public function getHeader(); - }