Permalink mini module

tazzytazzy - July 18, 2006 - 18:00

I wrote and quick a dirty permalink module for my site. It displays a "Permalink" at the bottom of the node since I use custom urls. I also might change my URL structure, so I figured I should offer permalinks for those wanting to link to content from other sites. See it in action at: http://www.warmy.com

Let me know if you found this useful.
-Mitch Schwenk

permalink.module

<?php
/**
* @file
* Allows permalinks to be displayed within nodes.  Usefull if you want others to link to your nodes but the url may change later.
* Written by Mitch Schwenk July 17, 2006 - tazzytazzy2 at yahoo (dawt) com
* Can be seen in action at: <a href="http://www.warmy.com/">http://www.warmy.com</a>
*/

/**
* Implementation of hook_help().
*/
function permalink_help($section) {
  switch (
$section) {
    case
'admin/help#permalink':
      return
'<p>'. t('The permalink module allows you to display permalinks for nodes.  Usefull for sites with custom URLs that may change in the future. </p>');
    case
'admin/modules#description':
      return
t('Display permalinks in nodes.');
   }
}

/**
* Implementation of hook_perm().
*/
function permalink_perm() {
  return array(
'access permalink');
}

/**
* Implementation of hook_link().
*/
function permalink_link($type, $node = 0, $main = 0) {
  if (
user_access('access permalink')) {
   
$links = array();
    if (
$type == 'node') {
      global
$base_url;
     
$url = $base_url . '/node/'.$node->nid;
     
$links[] = l(t('Permalink'), $url, array('title' => t('A link to this content that never changes.')));
    }
  }
  return
$links;
}
?>

'Cannot use string offset as an array' error and fix

jamesJonas - October 10, 2007 - 03:11

- Attempted 5.2 upgrade
- through error "PHP Fatal error: Cannot use string offset as an array in /var/www/html/xxxxx/includes/theme.inc on line 555,"
- this code may work a bit better

/**
* Implementation of hook_link().
*/
function permalink_link($type, $node = 0, $teaser = 0) {
  if (user_access('access permalink')) {
    if ($type == 'node') {
         $links = array();
         global $base_url;
         $url = $base_url . '/node/'.$node->nid;
         $links['permalink'] = array(
           'title' => t('Permalink'),
           'href' => $url,
           'attributes' => array('title' => t('A link to this content that should never change.'))
           );
    }
  }
  return $links;
}

James

 
 

Drupal is a registered trademark of Dries Buytaert.