| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Adds edit and delete links to node teasers and adds support for the
|
| 7 |
* Universal Edit Button.
|
| 8 |
*/
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Implementation of hook_menu().
|
| 12 |
*/
|
| 13 |
function admin_links_menu() {
|
| 14 |
$items['admin/settings/admin-links'] = array(
|
| 15 |
'title' => 'Admin links',
|
| 16 |
'description' => 'Settings for administration links in node teasers.',
|
| 17 |
'page callback' => 'drupal_get_form',
|
| 18 |
'page arguments' => array('admin_links_settings_form'),
|
| 19 |
'access arguments' => array('administer site configuration'),
|
| 20 |
'file' => 'admin_links.admin.inc',
|
| 21 |
);
|
| 22 |
|
| 23 |
return $items;
|
| 24 |
}
|
| 25 |
|
| 26 |
/**
|
| 27 |
* Implementation of hook_menu_alter().
|
| 28 |
*
|
| 29 |
* Change node delete menu callback to an accessible tab on the node page.
|
| 30 |
*/
|
| 31 |
function admin_links_menu_alter(&$callbacks) {
|
| 32 |
$callbacks['node/%node/delete']['type'] = MENU_LOCAL_TASK;
|
| 33 |
$callbacks['node/%node/delete']['weight'] = 2;
|
| 34 |
}
|
| 35 |
|
| 36 |
/**
|
| 37 |
* Implementation of hook_link().
|
| 38 |
*
|
| 39 |
* Adds node admin links to teasers.
|
| 40 |
*/
|
| 41 |
function admin_links_link($type, $node = NULL, $teaser = FALSE) {
|
| 42 |
$links = array();
|
| 43 |
|
| 44 |
if ($type == 'node') {
|
| 45 |
$edit_access = node_access('update', $node);
|
| 46 |
$delete_access = node_access('delete', $node);
|
| 47 |
if ($teaser && admin_links_var('admin_links_edit') && $edit_access) {
|
| 48 |
$links['admin_edit'] = array(
|
| 49 |
'title' => t('Edit'),
|
| 50 |
'href' => "node/{$node->nid}/edit",
|
| 51 |
'query' => drupal_get_destination(),
|
| 52 |
);
|
| 53 |
}
|
| 54 |
if ($teaser && admin_links_var('admin_links_delete') && $delete_access) {
|
| 55 |
$links['admin_delete'] = array(
|
| 56 |
'title' => t('Delete'),
|
| 57 |
'href' => "node/{$node->nid}/delete",
|
| 58 |
'query' => drupal_get_destination(),
|
| 59 |
);
|
| 60 |
}
|
| 61 |
if (!$teaser && admin_links_var('admin_links_universaledit') && $edit_access) {
|
| 62 |
drupal_add_link(array(
|
| 63 |
'rel' => 'alternate',
|
| 64 |
'type' => 'application/x-wiki',
|
| 65 |
'title' => t('Edit this page'),
|
| 66 |
'href' => url("node/{$node->nid}/edit", array('absolute' => TRUE)),
|
| 67 |
));
|
| 68 |
}
|
| 69 |
}
|
| 70 |
|
| 71 |
return $links;
|
| 72 |
}
|
| 73 |
|
| 74 |
/**
|
| 75 |
* Internal default variables for admin_links_var().
|
| 76 |
*/
|
| 77 |
function admin_links_variables() {
|
| 78 |
return array(
|
| 79 |
'admin_links_edit' => 1,
|
| 80 |
'admin_links_delete' => 0,
|
| 81 |
'admin_links_universaledit' => 0,
|
| 82 |
);
|
| 83 |
}
|
| 84 |
|
| 85 |
/**
|
| 86 |
* Internal implementation of variable_get().
|
| 87 |
*/
|
| 88 |
function admin_links_var($name) {
|
| 89 |
static $defaults = NULL;
|
| 90 |
if (!isset($defaults)) {
|
| 91 |
$defaults = admin_links_variables();
|
| 92 |
}
|
| 93 |
if (!isset($defaults[$name])) {
|
| 94 |
watchdog('admin_links', 'Default variable for %variable not found.', array('%variable' => $name));
|
| 95 |
}
|
| 96 |
return variable_get($name, isset($defaults[$name]) ? $defaults[$name] : NULL);
|
| 97 |
}
|