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

jeromev’s picture

Hi,
This is pretty cool.
I suggest

return theme('biblio_list', $full_node);

instead of

return theme_biblio_list($full_node);

Thanks!
jv

csc4’s picture

Looks really useful

gustav’s picture

Ulti, this is very valuable. Thank you!

bekasu’s picture

Upgrade to Biblio 6x and use Views or Panels.
Marking issue closed.

Liam Morland’s picture

Issue summary: View changes
Status: Needs review » Closed (outdated)

This version is no longer maintained. If this issue is still relevant to the Drupal 7 version, please re-open and provide details.