summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-12-03 20:21:50 +0000
committerDries Buytaert <dries@buytaert.net>2009-12-03 20:21:50 +0000
commitca8416e03637b99cf5846e6e3116ce4d2fcee5a0 (patch)
treec3017e25fa39d3f6caa46bc23fa2e7dd011412f3 /modules
parentd1a2de607e23da467c1366aca04ac5f61328a37a (diff)
downloadbrdo-ca8416e03637b99cf5846e6e3116ce4d2fcee5a0.tar.gz
brdo-ca8416e03637b99cf5846e6e3116ce4d2fcee5a0.tar.bz2
- Patch #542658 by sun: follow-up on move action 'tabs' out of local tasks.
Diffstat (limited to 'modules')
-rw-r--r--modules/blog/blog.module17
-rw-r--r--modules/blog/blog.pages.inc9
-rw-r--r--modules/blog/blog.test2
-rw-r--r--modules/forum/forum.module92
-rw-r--r--modules/forum/forums.tpl.php4
-rw-r--r--modules/node/node.admin.inc5
-rw-r--r--modules/node/node.module16
-rw-r--r--modules/taxonomy/taxonomy.module9
8 files changed, 107 insertions, 47 deletions
diff --git a/modules/blog/blog.module b/modules/blog/blog.module
index 294dfb17f..5e9d894bb 100644
--- a/modules/blog/blog.module
+++ b/modules/blog/blog.module
@@ -134,6 +134,23 @@ function blog_menu() {
}
/**
+ * Implements hook_menu_local_tasks_alter().
+ */
+function blog_menu_local_tasks_alter(&$data, $router_item, $root_path) {
+ // Add action link to 'node/add/blog' on 'blog' page.
+ if ($root_path == 'blog') {
+ $item = menu_get_item('node/add/blog');
+ if ($item['access']) {
+ $item['title'] = t('Create new blog entry');
+ $data['actions']['output'][] = array(
+ '#theme' => 'menu_local_action',
+ '#link' => $item,
+ );
+ }
+ }
+}
+
+/**
* Access callback for user blog pages.
*/
function blog_page_user_access($account) {
diff --git a/modules/blog/blog.pages.inc b/modules/blog/blog.pages.inc
index a605cfa1c..b12904bf1 100644
--- a/modules/blog/blog.pages.inc
+++ b/modules/blog/blog.pages.inc
@@ -70,15 +70,6 @@ function blog_page_last() {
global $user;
$build = array();
- if (user_access('create blog content')) {
- $items[] = l(t('Create new blog entry.'), "node/add/blog");
- $build['blog_actions'] = array(
- '#items' => $items,
- '#theme' => 'item_list',
- '#weight' => -1,
- );
- }
-
$query = db_select('node', 'n')->extend('PagerDefault');
$nids = $query
->fields('n', array('nid', 'sticky', 'created'))
diff --git a/modules/blog/blog.test b/modules/blog/blog.test
index 9a3734d4d..09d51a9fe 100644
--- a/modules/blog/blog.test
+++ b/modules/blog/blog.test
@@ -187,7 +187,7 @@ class BlogTestCase extends DrupalWebTestCase {
$this->assertResponse(200);
$this->assertTitle('Blogs | Drupal', t('Blog page was displayed'));
$this->assertText(t('Home'), t('Breadcrumbs were displayed'));
- $this->assertLink(t('Create new blog entry.'));
+ $this->assertLink(t('Create new blog entry'));
// Confirm a blog page was displayed per user.
$this->drupalGet('blog/' . $user->uid);
diff --git a/modules/forum/forum.module b/modules/forum/forum.module
index 8aa51713a..fb957d32e 100644
--- a/modules/forum/forum.module
+++ b/modules/forum/forum.module
@@ -137,6 +137,62 @@ function forum_menu() {
return $items;
}
+/**
+ * Implements hook_menu_local_tasks_alter().
+ */
+function forum_menu_local_tasks_alter(&$data, $router_item, $root_path) {
+ global $user;
+
+ // Add action link to 'node/add/forum' on 'forum' page.
+ if ($root_path == 'forum') {
+ $tid = (isset($router_item['page_arguments'][0]) ? $router_item['page_arguments'][0] : 0);
+ $forums = forum_get_forums($tid);
+ $parents = taxonomy_get_parents_all($tid);
+ if ($forums || $parents) {
+ $vid = variable_get('forum_nav_vocabulary', 0);
+ $vocabulary = taxonomy_vocabulary_load($vid);
+
+ $links = array();
+ // Loop through all bundles for forum taxonomy vocabulary field.
+ $field = field_info_field('taxonomy_' . $vocabulary->machine_name);
+ foreach ($field['bundles']['node'] as $type) {
+ if (node_access('create', $type)) {
+ $links[$type] = array(
+ '#theme' => 'menu_local_action',
+ '#link' => array(
+ 'title' => t('Add new @node_type', array('@node_type' => node_type_get_name($type))),
+ 'href' => 'node/add/' . str_replace('_', '-', $type) . '/' . $tid,
+ ),
+ );
+ }
+ }
+ 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 {
+ $links['login'] = array(
+ '#theme' => 'menu_local_action',
+ '#link' => array(
+ 'title' => t('<a href="@login">Login</a> to post new content in the forum.', array(
+ '@login' => url('user/login', array('query' => drupal_get_destination())),
+ )),
+ 'localized_options' => array('html' => TRUE),
+ ),
+ );
+ }
+ }
+ $data['actions']['output'] = array_merge($data['actions']['output'], $links);
+ }
+ }
+}
/**
* Implement hook_init().
@@ -647,6 +703,11 @@ function forum_url_outbound_alter(&$path, &$options, $original_path) {
* Array of object containing the forum information.
*/
function forum_get_forums($tid = 0) {
+ $cache = &drupal_static(__FUNCTION__, array());
+
+ if (isset($cache[$tid])) {
+ return $cache[$tid];
+ }
$forums = array();
$vid = variable_get('forum_nav_vocabulary', 0);
@@ -708,6 +769,8 @@ function forum_get_forums($tid = 0) {
$forums[$forum->tid] = $forum;
}
+ $cache[$tid] = $forums;
+
return $forums;
}
@@ -846,32 +909,6 @@ function template_preprocess_forums(&$variables) {
drupal_set_title($title);
if ($variables['forums_defined'] = count($variables['forums']) || count($variables['parents'])) {
- // Format the "post new content" links listing.
- $forum_types = array();
-
- // Loop through all bundles for forum taxonomy vocabulary field.
- $field = field_info_field('taxonomy_' . $vocabulary->machine_name);
- foreach ($field['bundles']['node'] as $type) {
- // Check if the current user has the 'create' permission for this node type.
- if (node_access('create', $type)) {
- // Fetch the "General" name of the content type;
- // Push the link with title and url to the array.
- $forum_types[$type] = array('title' => t('Add new @node_type', array('@node_type' => node_type_get_name($type))), 'href' => 'node/add/' . str_replace('_', '-', $type) . '/' . $variables['tid']);
- }
- }
-
- if (empty($forum_types)) {
- // The user is logged-in; but denied access to create any new forum content type.
- if ($user->uid) {
- $forum_types['disallowed'] = array('title' => t('You are not allowed to post new content in the forum.'));
- }
- // The user is not logged-in; and denied access to create any new forum content type.
- else {
- $forum_types['login'] = array('title' => t('<a href="@login">Login</a> to post new content in the forum.', array('@login' => url('user/login', array('query' => drupal_get_destination())))), 'html' => TRUE);
- }
- }
- $variables['links'] = $forum_types;
-
if (!empty($variables['forums'])) {
$variables['forums'] = theme('forum_list', $variables);
}
@@ -905,8 +942,7 @@ function template_preprocess_forums(&$variables) {
}
else {
- drupal_set_title(t('No forums defined'), PASS_THROUGH);
- $variables['links'] = array();
+ drupal_set_title(t('No forums defined'));
$variables['forums'] = '';
$variables['topics'] = '';
}
diff --git a/modules/forum/forums.tpl.php b/modules/forum/forums.tpl.php
index 0db6c4d48..2c9e2efa0 100644
--- a/modules/forum/forums.tpl.php
+++ b/modules/forum/forums.tpl.php
@@ -7,9 +7,6 @@
* containers as well as forum topics.
*
* Variables available:
- * - $links: An array of links that allow a user to post new forum topics.
- * It may also contain a string telling a user they must log in in order
- * to post.
* - $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.
@@ -20,7 +17,6 @@
?>
<?php if ($forums_defined): ?>
<div id="forum">
- <?php print theme('links', array('links' => $links)); ?>
<?php print $forums; ?>
<?php print $topics; ?>
</div>
diff --git a/modules/node/node.admin.inc b/modules/node/node.admin.inc
index e70ab1224..ebdac0610 100644
--- a/modules/node/node.admin.inc
+++ b/modules/node/node.admin.inc
@@ -391,11 +391,6 @@ function node_admin_content($form, $form_state) {
if (isset($form_state['values']['operation']) && $form_state['values']['operation'] == 'delete') {
return node_multiple_delete_confirm($form, $form_state, array_filter($form_state['values']['nodes']));
}
- // Show the 'add new content' link.
- $form['add_content'] = array(
- '#access' => _node_add_access(),
- '#markup' => theme('links', array('links' => array(array('title' => t('Add new content'), 'href' => 'node/add')), 'attributes' => array('class' => array('action-links')))),
- );
$form['filter'] = node_filter_form();
$form['#submit'][] = 'node_filter_form_submit';
$form['#theme'] = 'node_filter_form';
diff --git a/modules/node/node.module b/modules/node/node.module
index ffaa3a0f7..71e7512ff 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -1953,6 +1953,22 @@ function node_menu() {
}
/**
+ * Implements hook_menu_local_tasks_alter().
+ */
+function node_menu_local_tasks_alter(&$data, $router_item, $root_path) {
+ // Add action link to 'node/add' on 'admin/content' page.
+ if ($root_path == 'admin/content') {
+ $item = menu_get_item('node/add');
+ if ($item['access']) {
+ $data['actions']['output'][] = array(
+ '#theme' => 'menu_local_action',
+ '#link' => $item,
+ );
+ }
+ }
+}
+
+/**
* Title callback for a node type.
*/
function node_type_page_title($type) {
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module
index 79826cc19..83c71e06e 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -646,6 +646,12 @@ function taxonomy_get_parents($tid, $key = 'tid') {
* Find all ancestors of a given term ID.
*/
function taxonomy_get_parents_all($tid) {
+ $cache = &drupal_static(__FUNCTION__, array());
+
+ if (isset($cache[$tid])) {
+ return $cache[$tid];
+ }
+
$parents = array();
if ($term = taxonomy_term_load($tid)) {
$parents[] = $term;
@@ -655,6 +661,9 @@ function taxonomy_get_parents_all($tid) {
$n++;
}
}
+
+ $cache[$tid] = $parents;
+
return $parents;
}