commit b07aa367f82e882c066714f2870d1eee9cd9037d Author: Steve Purkiss Date: Sun Dec 9 14:55:07 2012 +0000 1853072-10-953214-52-new_changes diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 0276998..4ae8041 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -61,7 +61,7 @@ function forum_theme() { return array( 'forums' => array( 'template' => 'forums', - 'variables' => array('forums' => NULL, 'topics' => NULL, 'parents' => NULL, 'tid' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL), + 'variables' => array('access_error' => NULL, 'forums' => NULL, 'topics' => NULL, 'parents' => NULL, 'tid' => NULL, 'sortby' => NULL, 'forum_per_page' => NULL), ), 'forum_list' => array( 'template' => 'forum-list', @@ -186,33 +186,37 @@ function forum_menu_local_tasks_alter(&$data, $router_item, $root_path) { ); } } - if (empty($links)) { - // Authenticated user does not have access to create new topics. - if ($user->uid) { - $links['disallowed'] = array( - '#theme' => 'menu_local_action', - '#link' => array( - 'title' => t('You are not allowed to post new content in the forum.'), - ), - ); - } - // Anonymous user does not have access to create new topics. - else { - // If authenticated users can post new topic, provide a login link. - if (user_role_has_permission(DRUPAL_AUTHENTICATED_RID, 'create forum content')) { + // We only output a link if we are certain that users will get permission + // to post new content in the forum by logging in. + if (empty($links) && !$user->uid) { + // If authenticated users can post new topic, provide a login link. + if (user_role_has_permission(DRUPAL_AUTHENTICATED_RID, 'create forum content')) { + $destination = drupal_get_destination(); + // Users can register themselves. + if (config('user.settings')->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY) { + $links['login'] = array( + '#theme' => 'menu_local_action', + '#link' => array( + 'title' => t('Log in or register to post new content in the forum.'), + 'href' => 'user', + 'localized_options' => $destination, + ), + ); + } + else { + // Only admins can add new users, no public registration. $links['login'] = array( '#theme' => 'menu_local_action', '#link' => array( - 'title' => t('Log in to post new content in the forum.', array( - '@login' => url('user/login', array('query' => drupal_get_destination())), - )), - 'localized_options' => array('html' => TRUE), + 'title' => t('Log in to post new content in the forum.'), + 'href' => 'user/login', + 'localized_options' => $destination, ), ); } } + $data['actions']['output'] = array_merge($data['actions']['output'], $links); } - $data['actions']['output'] = array_merge($data['actions']['output'], $links); } } } diff --git a/core/modules/forum/forum.pages.inc b/core/modules/forum/forum.pages.inc index 0f41bd3..8f9ffbb 100644 --- a/core/modules/forum/forum.pages.inc +++ b/core/modules/forum/forum.pages.inc @@ -18,6 +18,8 @@ * @see forum_menu() */ function forum_page($forum_term = NULL) { + global $user; + $config = config('forum.settings'); if (!isset($forum_term)) { // On the main page, display all the top-level forums. @@ -34,5 +36,16 @@ function forum_page($forum_term = NULL) { $topics = ''; } - return theme('forums', array('forums' => $forum_term->forums, 'topics' => $topics, 'parents' => $forum_term->parents, 'tid' => $forum_term->tid, 'sortby' => $sortby, 'forums_per_page' => $forum_per_page)); -} + // Loop through all bundles for forum taxonomy vocabulary field. + $field = field_info_field('taxonomy_forums'); + $access_error = NULL; + foreach ($field['bundles']['node'] as $type) { + if (!node_access('create', $type)) { + if ($user->uid) { + // Authenticated user does not have access to create new topics. + $access_error = t('You are not allowed to post new content in the forum.'); + } + } + } + return theme('forums', array('access_error' => $access_error, 'forums' => $forum_term->forums, 'topics' => $topics, 'parents' => $forum_term->parents, 'tid' => $forum_term->tid, 'sortby' => $sortby, 'forums_per_page' => $forum_per_page)); +} \ No newline at end of file diff --git a/core/modules/forum/templates/forums.tpl.php b/core/modules/forum/templates/forums.tpl.php index 6a0e02e..98e5e3f 100644 --- a/core/modules/forum/templates/forums.tpl.php +++ b/core/modules/forum/templates/forums.tpl.php @@ -7,6 +7,7 @@ * May contain forum containers as well as forum topics. * * Available variables: + * - $access_error: Contains a message if user does not have access to post new content * - $forums: The forums to display (as processed by forum-list.tpl.php). * - $topics: The topics to display (as processed by forum-topic-list.tpl.php). * - $forums_defined: A flag to indicate that the forums are configured. @@ -18,6 +19,7 @@ ?>
+