diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index c58d7b1..8f165f2 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -98,6 +98,8 @@ function forum_menu() { ); $items['forum/%forum'] = array( 'title' => 'Forums', + 'title callback' => 'entity_page_label', + 'title arguments' => array(1), 'route_name' => 'forum_page', ); $items['admin/structure/forum'] = array( @@ -253,15 +255,15 @@ function forum_uri($forum) { function forum_taxonomy_term_load(array $entities) { $config = config('forum.settings'); $vid = $config->get('vocabulary'); - foreach ($entities as $tid => &$forum_term) { - if ($forum_term->bundle() != $vid) { + foreach ($entities as $tid => $entity) { + if ($entity->bundle() != $vid) { // Not a forum term. continue; } // Determine if the requested term is a container. - if (in_array($forum_term->id(), $config->get('containers'))) { - $forum_term->container = TRUE; + if (in_array($entity->id(), $config->get('containers'))) { + $entity->container = TRUE; } } return $entities; diff --git a/core/modules/forum/forum.routing.yml b/core/modules/forum/forum.routing.yml index 244db7f..39ebaaa 100644 --- a/core/modules/forum/forum.routing.yml +++ b/core/modules/forum/forum.routing.yml @@ -4,18 +4,21 @@ forum_delete: _form: 'Drupal\forum\Form\DeleteForm' requirements: _permission: 'administer forums' + forum_settings: pattern: '/admin/structure/forum/settings' defaults: _form: '\Drupal\forum\ForumSettingsForm' requirements: _permission: 'administer forums' + forum_index: pattern: '/forum' defaults: _content: 'Drupal\forum\Controller\ForumController::forumIndex' requirements: _permission: 'access content' + forum_page: pattern: '/forum/{taxonomy_term}' defaults: diff --git a/core/modules/forum/lib/Drupal/forum/Controller/ForumController.php b/core/modules/forum/lib/Drupal/forum/Controller/ForumController.php index bc9b538..87d5fa4 100644 --- a/core/modules/forum/lib/Drupal/forum/Controller/ForumController.php +++ b/core/modules/forum/lib/Drupal/forum/Controller/ForumController.php @@ -80,8 +80,6 @@ public function forumPage(TermInterface $taxonomy_term) { // Get forum details $taxonomy_term->forums = $this->forumManager->getChildren($this->config->get('vocabulary'), $taxonomy_term->id()); $taxonomy_term->parents = $this->forumManager->getParents($taxonomy_term->id()); - // Page title. - drupal_set_title($taxonomy_term->label()); if ($taxonomy_term->container) { // Add RSS feed for forums. drupal_add_feed('taxonomy/term/' . $taxonomy_term->id() . '/feed', 'RSS - ' . $taxonomy_term->label()); @@ -93,19 +91,7 @@ public function forumPage(TermInterface $taxonomy_term) { else { $topics = ''; } - - $build = array( - '#theme' => 'forums', - '#forums' => $taxonomy_term->forums, - '#topics' => $topics, - '#parents' => $taxonomy_term->parents, - '#tid' => $taxonomy_term->id(), - '#sortby' => $this->config->get('topics.order'), - '#forums_per_page' => $this->config->get('topics.page_limit'), - ); - // @todo Make this a library - see https://drupal.org/node/2028113. - $build['#attached']['css'][] = drupal_get_path('module', 'forum') . '/forum.css'; - return $build; + return $this->build($taxonomy_term->forums, $taxonomy_term->id(), $topics, $taxonomy_term->parents); } /** @@ -118,19 +104,39 @@ public function forumIndex() { $vocabularies = $this->storageController->load(array($this->config->get('vocabulary'))); $vocabulary = reset($vocabularies); $index = $this->forumManager->getIndex(); - // Set the page title to forum's vocabulary name. - drupal_set_title($vocabulary->label()); if (empty($index->forums)) { // Root of empty forum. drupal_set_title(t('No forums defined')); } + else { + // Set the page title to forum's vocabulary name. + drupal_set_title($vocabulary->label()); + } + return $this->build($index->forums, $index->id()); + } + /** + * Returns a renderable forum index page array. + * + * @param array $forums + * A list of forums. + * @param int $tid + * The taxonomy term of the forum. + * @param string $topics + * The topics of this forum. + * @param array $parents + * The parent forums in relation this forum. + * + * @return array + * A render array. + */ + protected function build($forums, $tid, $topics = '', $parents = array()) { $build = array( '#theme' => 'forums', - '#forums' => $index->forums, - '#topics' => '', - '#parents' => array(), - '#tid' => $index->id(), + '#forums' => $forums, + '#topics' => $topics, + '#parents' => $parents, + '#tid' => $tid, '#sortby' => $this->config->get('topics.order'), '#forums_per_page' => $this->config->get('topics.page_limit'), ); diff --git a/core/modules/forum/lib/Drupal/forum/ForumBreadcrumbBuilder.php b/core/modules/forum/lib/Drupal/forum/ForumBreadcrumbBuilder.php index 604ee08..4e82686 100644 --- a/core/modules/forum/lib/Drupal/forum/ForumBreadcrumbBuilder.php +++ b/core/modules/forum/lib/Drupal/forum/ForumBreadcrumbBuilder.php @@ -60,10 +60,7 @@ public function __construct(EntityManager $entity_manager, ConfigFactory $config public function build(array $attributes) { // @todo This only works for legacy routes. Once node/% and forum/% are // converted to the new router this code will need to be updated. - if (isset($attributes['drupal_menu_item']) && - ($item = $attributes['drupal_menu_item']) && - $item['path'] == 'node/%') { - + if (isset($attributes['drupal_menu_item']) && ($item = $attributes['drupal_menu_item']) && $item['path'] == 'node/%') { $node = $item['map'][1]; // Load the object in case of missing wildcard loaders. $node = is_object($node) ? $node : node_load($node); @@ -72,9 +69,7 @@ public function build(array $attributes) { } } - if (!empty($attributes['_route']) && - $attributes['_route'] == 'forum_page' && - isset($attributes['taxonomy_term'])) { + if (!empty($attributes['_route']) && $attributes['_route'] == 'forum_page' && isset($attributes['taxonomy_term'])) { $breadcrumb = $this->forumTermBreadcrumb($attributes['taxonomy_term']); } diff --git a/core/modules/forum/lib/Drupal/forum/ForumManager.php b/core/modules/forum/lib/Drupal/forum/ForumManager.php index dbc56bf..bdc9ceb 100644 --- a/core/modules/forum/lib/Drupal/forum/ForumManager.php +++ b/core/modules/forum/lib/Drupal/forum/ForumManager.php @@ -53,11 +53,11 @@ class ForumManager implements ForumManagerInterface { protected $entityManager; /** - * Database service + * Database connection * * @var \Drupal\Core\Database\Connection */ - protected $database; + protected $connection; /** * Array of last post information keyed by forum (term) id. @@ -108,15 +108,15 @@ class ForumManager implements ForumManagerInterface { * The config factory service. * @param \Drupal\Core\Entity\EntityManager $entity_manager * The entity manager service. - * @param \Drupal\Core\Database\Connection $database + * @param \Drupal\Core\Database\Connection $connection * The current database connection. * @param \Drupal\field\FieldInfo $field_info * The field info service. */ - public function __construct(ConfigFactory $config_factory, EntityManager $entity_manager, Connection $database, FieldInfo $field_info) { + public function __construct(ConfigFactory $config_factory, EntityManager $entity_manager, Connection $connection, FieldInfo $field_info) { $this->config = $config_factory->get('forum.settings'); $this->entityManager = $entity_manager; - $this->database = $database; + $this->connection = $connection; $this->fieldInfo = $field_info; } @@ -142,7 +142,7 @@ public function getTopics($tid) { } } - $query = $this->database->select('forum_index', 'f') + $query = $this->connection->select('forum_index', 'f') ->extend('Drupal\Core\Database\Query\PagerSelectExtender') ->extend('Drupal\Core\Database\Query\TableSortExtender'); $query->fields('f'); @@ -154,7 +154,7 @@ public function getTopics($tid) { ->orderByHeader($forum_topic_list_header) ->limit($forum_per_page); - $count_query = $this->database->select('forum_index', 'f'); + $count_query = $this->connection->select('forum_index', 'f'); $count_query->condition('f.tid', $tid); $count_query->addExpression('COUNT(*)'); $count_query->addTag('node_access'); @@ -169,7 +169,7 @@ public function getTopics($tid) { if ($nids) { $nodes = $this->entityManager->getStorageController('node')->load($nids); - $query = $this->database->select('node_field_data', 'n') + $query = $this->conection->select('node_field_data', 'n') ->extend('Drupal\Core\Database\Query\TableSortExtender'); $query->fields('n', array('nid')); @@ -290,10 +290,10 @@ protected function getTopicOrder($sortby) { } /** - * Util method to ensure comment_num_new is behind a method. + * Provides a new comment number. * * @param int $nid - * Node id. + * Node ID. * @param int $timestamp * Timestamp of last read. * @@ -318,7 +318,7 @@ protected function lastVisit($nid) { global $user; if (empty($this->history[$nid])) { - $result = $this->database->select('history', 'h') + $result = $this->connection->select('history', 'h') ->fields('h', array('nid', 'timestamp')) ->condition('uid', $user->uid) ->execute(); @@ -330,7 +330,7 @@ protected function lastVisit($nid) { } /** - * Utility method to get the last post information for the given forum tid. + * Provides the last post information for the given forum tid. * * @param int $tid * The forum tid. @@ -343,7 +343,7 @@ protected function getLastPost($tid) { return $this->lastPostData[$tid]; } // Query "Last Post" information for this forum. - $query = $this->database->select('node_field_data', 'n'); + $query = $this->connection->select('node_field_data', 'n'); $query->join('forum', 'f', 'n.vid = f.vid AND f.tid = :tid', array(':tid' => $tid)); $query->join('node_comment_statistics', 'ncs', 'n.nid = ncs.nid'); $query->join('users', 'u', 'ncs.last_comment_uid = u.uid'); @@ -371,18 +371,18 @@ protected function getLastPost($tid) { } /** - * Utility method to fetch statistics for a forum. + * Provides statistics for a forum. * * @param int $tid * The forum tid. * - * @return \stdClass|NULL - * Statistics for the given forum if statistics exist, else NULL + * @return \stdClass|null + * Statistics for the given forum if statistics exist, else NULL. */ protected function getForumStatistics($tid) { if (empty($this->forumStatistics)) { // Prime the statistics. - $query = $this->database->select('node_field_data', 'n'); + $query = $this->connection->select('node_field_data', 'n'); $query->join('node_comment_statistics', 'ncs', 'n.nid = ncs.nid'); $query->join('forum', 'f', 'n.vid = f.vid'); $query->addExpression('COUNT(n.nid)', 'topic_count'); diff --git a/core/modules/forum/lib/Drupal/forum/ForumManagerInterface.php b/core/modules/forum/lib/Drupal/forum/ForumManagerInterface.php index fad4d0c..8b5f7c4 100644 --- a/core/modules/forum/lib/Drupal/forum/ForumManagerInterface.php +++ b/core/modules/forum/lib/Drupal/forum/ForumManagerInterface.php @@ -7,7 +7,7 @@ namespace Drupal\forum; -use Drupal\Core\Entity\EntityInterface; +use Drupal\node\Plugin\Core\Entity\NodeInterface; /** * Provides forum manager interface. @@ -18,7 +18,7 @@ * Gets list of forum topics. * * @param int $tid - * Term id. + * Term ID. * * @return array * Array of topics. @@ -29,9 +29,9 @@ public function getTopics($tid); * Utility method to fetch the child forums for a given forum. * * @param int $vid - * The forum vocabulary id. + * The forum vocabulary ID. * @param int $tid - * The forum id to fetch the children for. + * The forum ID to fetch the children for. * * @return array * Array of children. @@ -57,7 +57,7 @@ public function resetCache(); * Protected function to wrap call to taxonomy_term_load_parents_all. * * @param int $tid - * Term id. + * Term ID. * * @return array * Array of parent terms. @@ -70,12 +70,12 @@ public function getParents($tid); /** * Checks whether a node can be used in a forum, based on its content type. * - * @param \Drupal\Core\Entity\EntityInterface $node + * @param \Drupal\node\Plugin\Core\Entity\NodeInterface $node * A node entity. * * @return bool * Boolean indicating if the node can be assigned to a forum. */ - public function checkNodeType(EntityInterface $node); + public function checkNodeType(NodeInterface $node); }