Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi, just thought I would post this snippet of code for formatting CCK Node References as Biblio references. I am new to Drupal and really needed this feature to add a way for my users to select publications to display on their staff pages. If the node types aren't biblio ones it just defaults to creating a title link. I currently have this code in my own module but I think it would be good to see it added to Biblio for others to use.
/**
* Implementation of hook_field_formatter_info().
*/
function biblio_field_formatter_info() {
return array(
'biblio' => array(
'label' => 'Biblio (reference)',
'field types' => array('nodereference'),
),
);
}
/**
* Implementation of hook_field_formatter().
*/
function biblio_field_formatter($field, $item, $formatter, $node) {
if (!isset($item['nid'])) {
return '';
}
switch ($formatter) {
case 'biblio':
$full_node = node_load($item['nid']);
if ($full_node->type == 'biblio') {
return theme_biblio_list($full_node);
}
//If not a biblio node just output a title link.
else {
return l($full_node->title, 'node/'. $item['nid']);
}
break;
}
}
Comments
Comment #1
jeromev CreditAttribution: jeromev commentedHi,
This is pretty cool.
I suggest
return theme('biblio_list', $full_node);
instead of
return theme_biblio_list($full_node);
Thanks!
jv
Comment #2
csc4 CreditAttribution: csc4 commentedLooks really useful
Comment #3
gustav CreditAttribution: gustav commentedUlti, this is very valuable. Thank you!
Comment #4
bekasu CreditAttribution: bekasu commentedUpgrade to Biblio 6x and use Views or Panels.
Marking issue closed.
Comment #5
Liam MorlandThis version is no longer maintained. If this issue is still relevant to the Drupal 7 version, please re-open and provide details.