Commit 478a624a authored by webchick's avatar webchick

Issue #148145 by andypost, cburschka, Gábor Hojtsy, alexweber, sun: Fixed...

Issue #148145 by andypost, cburschka, Gábor Hojtsy, alexweber, sun: Fixed 'Forums' title is not localized.
parent 951a389e
......@@ -100,6 +100,8 @@ function forum_menu() {
);
$items['forum/%forum_forum'] = array(
'title' => 'Forums',
'title callback' => 'entity_page_label',
'title arguments' => array(1),
'page callback' => 'forum_page',
'page arguments' => array(1),
'access arguments' => array('access content'),
......@@ -710,11 +712,11 @@ function forum_forum_load($tid = NULL) {
return $cache[$tid] = FALSE;
}
}
// If $tid is 0, create an empty object to hold the child terms.
// If $tid is 0, create an empty entity to hold the child terms.
elseif ($tid === 0) {
$forum_term = (object) array(
$forum_term = entity_create('taxonomy_term', array(
'tid' => 0,
);
));
}
// Determine if the requested term is a container.
......@@ -989,32 +991,6 @@ function forum_preprocess_block(&$variables) {
* @see forums.tpl.php
*/
function template_preprocess_forums(&$variables) {
global $user;
$config = config('forum.settings');
$vid = $config->get('vocabulary');
$vocabulary = taxonomy_vocabulary_load($vid);
$title = !empty($vocabulary->name) ? $vocabulary->name : '';
// Breadcrumb navigation:
$breadcrumb[] = l(t('Home'), NULL);
if ($variables['tid']) {
$breadcrumb[] = l($vocabulary->name, 'forum');
}
if ($variables['parents']) {
$variables['parents'] = array_reverse($variables['parents']);
foreach ($variables['parents'] as $p) {
if ($p->tid == $variables['tid']) {
$title = $p->label();
}
else {
$breadcrumb[] = l($p->label(), 'forum/' . $p->tid);
}
}
}
drupal_set_breadcrumb($breadcrumb);
drupal_set_title($title);
if ($variables['forums_defined'] = count($variables['forums']) || count($variables['parents'])) {
if (!empty($variables['forums'])) {
$variables['forums'] = theme('forum_list', $variables);
......@@ -1023,9 +999,8 @@ function template_preprocess_forums(&$variables) {
$variables['forums'] = '';
}
if ($variables['tid'] && !in_array($variables['tid'], $config->get('containers'))) {
if ($variables['tid'] && array_search($variables['tid'], config('forum.settings')->get('containers')) === FALSE) {
$variables['topics'] = theme('forum_topic_list', $variables);
drupal_add_feed('taxonomy/term/' . $variables['tid'] . '/feed', 'RSS - ' . $title);
}
else {
$variables['topics'] = '';
......@@ -1049,7 +1024,6 @@ function template_preprocess_forums(&$variables) {
}
else {
drupal_set_title(t('No forums defined'));
$variables['forums'] = '';
$variables['topics'] = '';
}
......
......@@ -19,16 +19,46 @@
*/
function forum_page($forum_term = NULL) {
$config = config('forum.settings');
$vocabulary = entity_load('taxonomy_vocabulary', $config->get('vocabulary'));
if (!isset($forum_term)) {
// On the main page, display all the top-level forums.
$forum_term = forum_forum_load(0);
// Set the page title to forum's vocabulary name.
drupal_set_title($vocabulary->label());
}
// Breadcrumb navigation.
$breadcrumb[] = l(t('Home'), NULL);
if ($forum_term->tid) {
// Parent of all forums is the vocabulary name.
$breadcrumb[] = l($vocabulary->label(), 'forum');
}
// Add all parent forums to breadcrumbs.
if ($forum_term->parents) {
foreach (array_reverse($forum_term->parents) as $parent) {
if ($parent->id() != $forum_term->tid) {
$breadcrumb[] = l($parent->label(), 'forum/' . $parent->id());
}
}
}
drupal_set_breadcrumb($breadcrumb);
if ($forum_term->tid && array_search($forum_term->tid, $config->get('containers')) === FALSE) {
// Add RSS feed for forums.
drupal_add_feed('taxonomy/term/' . $forum_term->id() . '/feed', 'RSS - ' . $forum_term->label());
}
if (empty($forum_term->forums) && empty($forum_term->parents)) {
// Root of empty forum.
drupal_set_title(t('No forums defined'));
}
$forum_per_page = $config->get('topics.page_limit');
$sortby = $config->get('topics.order');
$sort_by = $config->get('topics.order');
if (empty($forum_term->container)) {
$topics = forum_get_topics($forum_term->tid, $sortby, $forum_per_page);
$topics = forum_get_topics($forum_term->tid, $sort_by, $forum_per_page);
}
else {
$topics = '';
......@@ -40,12 +70,9 @@ function forum_page($forum_term = NULL) {
'#topics' => $topics,
'#parents' => $forum_term->parents,
'#tid' => $forum_term->tid,
'#sortby' => $sortby,
'#sortby' => $sort_by,
'#forums_per_page' => $forum_per_page,
);
$build['#attached']['css'][] = drupal_get_path('module', 'forum') . '/forum.css';
// @todo Returning a render array causes template_preprocess_forums() to be
// invoked too late and the breadcrumb is rendered before that callback
// adjusted it.
return drupal_render($build);
return $build;
}
......@@ -220,6 +220,15 @@ function testForum() {
$this->drupalGet('forum/' . $this->forum['tid']);
$this->drupalPost("node/$node->nid/edit", array(), t('Save'));
$this->assertResponse(200);
// Test the root forum page title change.
$this->drupalGet('forum');
$this->assertTitle(t('Forums | Drupal'));
$vocabulary = entity_load('taxonomy_vocabulary', $this->forum['vid']);
$vocabulary->set('name', 'Discussions');
$vocabulary->save();
$this->drupalGet('forum');
$this->assertTitle(t('Discussions | Drupal'));
}
/**
......@@ -267,7 +276,7 @@ private function doAdminTests($user) {
// Edit forum taxonomy.
// Restoration of the settings fails and causes subsequent tests to fail.
$this->forumContainer = $this->editForumTaxonomy();
$this->forumContainer = $this->editForumVocabulary();
// Create forum container.
$this->forumContainer = $this->createForum('container');
// Verify "edit container" link exists and functions correctly.
......@@ -328,38 +337,36 @@ private function doAdminTests($user) {
/**
* Edits the forum taxonomy.
*/
function editForumTaxonomy() {
function editForumVocabulary() {
// Backup forum taxonomy.
$vid = config('forum.settings')->get('vocabulary');
$original_settings = taxonomy_vocabulary_load($vid);
// Generate a random name/description.
$title = $this->randomName(10);
$description = $this->randomName(100);
$original_vocabulary = entity_load('taxonomy_vocabulary', $vid);
// Generate a random name and description.
$edit = array(
'name' => $title,
'description' => $description,
'name' => $this->randomName(10),
'description' => $this->randomName(100),
);
// Edit the vocabulary.
$this->drupalPost('admin/structure/taxonomy/' . $original_settings->id() . '/edit', $edit, t('Save'));
$this->drupalPost('admin/structure/taxonomy/' . $original_vocabulary->id() . '/edit', $edit, t('Save'));
$this->assertResponse(200);
$this->assertRaw(t('Updated vocabulary %name.', array('%name' => $title)), 'Vocabulary was edited');
$this->assertRaw(t('Updated vocabulary %name.', array('%name' => $edit['name'])), 'Vocabulary was edited');
// Grab the newly edited vocabulary.
$this->container->get('plugin.manager.entity')->getStorageController('taxonomy_vocabulary')->resetCache();
$current_settings = taxonomy_vocabulary_load($vid);
$current_vocabulary = entity_load('taxonomy_vocabulary', $vid);
// Make sure we actually edited the vocabulary properly.
$this->assertEqual($current_settings->name, $title, 'The name was updated');
$this->assertEqual($current_settings->description, $description, 'The description was updated');
// Restore the original vocabulary.
taxonomy_vocabulary_save($original_settings);
drupal_static_reset('taxonomy_vocabulary_load');
$current_settings = taxonomy_vocabulary_load($vid);
$this->assertEqual($current_settings->name, $original_settings->name, 'The original vocabulary settings were restored');
$this->assertEqual($current_vocabulary->name, $edit['name'], 'The name was updated');
$this->assertEqual($current_vocabulary->description, $edit['description'], 'The description was updated');
// Restore the original vocabulary's name and description.
$current_vocabulary->set('name', $original_vocabulary->name);
$current_vocabulary->set('description', $original_vocabulary->description);
$current_vocabulary->save();
// Reload vocabulary to make sure changes are saved.
$current_vocabulary = entity_load('taxonomy_vocabulary', $vid);
$this->assertEqual($current_vocabulary->name, $original_vocabulary->name, 'The original vocabulary settings were restored');
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment