I realy love Drupal and especially CCK related stuff. But the best of all is referencing one information (node) with any other in a structured way. CCK with nodereference does a wonderful thing to help me build prototypes and production sites that are more than a CMS, they are becoming real Knowledgebase Applications and much more in the future.
To be able to see all reverse links that point to the node that is actually viewed, I decided to write a php snippet for a block. The block now display all referrer nodes and groups them by node-type.
what it does:
- detect the nid of the actual viewed node
- go through the referrers
- group the output by node-type (this is accidentially sorted at the moment)
It is all not clean and I could never get through all the array stuff that would be needed to 'really' sort the items, but I hope that someone of the realcoders can take this idea andput it inside nodereference.module that a standardized block for this exists.
Additional wishes:
- I would like to add other fields of the referrer-node, but dont have the knowhow of cck module how to get it with a snippet. Has someone a map of all the wonderful array monsters that I maybe never can fight with my littlephp-snippet sword? ;-)
Please find in the attached zip file the php-snippet and a Screenshot.
<?php
global $user;
// identify node id for current viewed node
function nid(){
static $nid; if(isset($nid)){return $nid;}
$q = $_REQUEST['q'];
$p = drupal_get_normal_path($q);
$nid = array_pop(explode("/",$p));
if (substr($p,0,4)<>'node') {$nid=0;}
// check if it is a node,
// and not a argument number at the end of the path
return $nid;
}
if (nid()>0) {
$referrers = nodereference_get_referrers(nid());
$content_type_grouping = '';
foreach($referrers as $referrer) {
// group output by node type
if ($content_type_grouping <> $referrer->type) {
$content_type_grouping = $referrer->type;
$output .= '<br>'.substr($referrer->type,8).'<br>';
}
// Check Users View Permission
if (node_access('view', $referrer->nid, $user->uid)) {
$output .= '<a href="'.$referrer->nid.'">'.$referrer->title.'</a><br>';
}
}
return $output;
}
?>
Comments
Comment #1
biohabit commentedI'm using the CCK for almost the exact same purpose, but when I enable the above PHP code and go to a node that includes nodereferences I get the white screen of death. Any ideas?
Comment #2
biohabit commentedWhat version of the CCK was this developed against? I'm using the CVS from June 12th.
Comment #3
biohabit commentedHow the heck was I able to rename this ticket when I'm not the owner? I don't remember the exact title so this was a guess.
Comment #4
robert.redl@easytouch.cc commentedThanks for your feedback,
I am using for this at the moment
- Drupal Version 7.2,
- CCK cvs Version
/modules/content.module Version 1.64 2006/06/12 19:36:54 JonBob Exp $
With Drupal 4.6.x I have to figure out how the actual node-id can be fetched.
Should be something like $node->nid. If I find time, I will check this out for the 4.6 Users.
The title change was maybe possible, because no owner was set? I also dont know the miracles of the issue system? ;-)
Comment #5
robert.redl@easytouch.cc commentedOK, The above example for the block works only with the following Versions:
1. CCK Version Drupal 4.7.0
2. The followingPatch must be applied to the file /modules/cck/nodereference.module
http://drupal.org/files/issues/nodereference.module_5.patch
Apply like this (if you have Linux Shell access with CVS
# patch nodereference.module < nodereference.module_5.patch
See the attachment to thiscomment for the already patchednodereference.module
Comment #6
robert.redl@easytouch.cc commentedIf you want to use this with
- CCK Module CVS version
You have additionaly to patch nodereference.module, to add the following function to the end of
content.module
It seems thatsomeonehadlost the function from CCK 4.70 up to CVS, but a lot of patches and sandboxes I have seen the last days use it. Let's wait, until the Pro's sort this out and get all the interesting referrers and date modules on the track. CCK and its newest patches really rules!
Comment #7
karens commentedThere is another issue with more current activity on this topic at http://drupal.org/node/60756, so marking as duplicate.