I'm hoping this is a relatively easy question (perhaps I'm looking in the wrong place for the data I seek). I am creating a site that depends heavily on using cck and contemplate to manipulate node contents on the display end; that is, a relatively basic set of fields (including node references) are in play but I manipulate their contents with a content template to display the field data in a number of different ways to the end user on the node page.

As such I've found the nid data generated in by the node_ref field very helpful - it is made available in an array in the $node:

$node->field_noderef (array)
    $node->field_noderef[0] (array)
        $node->field_noderef[0]['nid']
            5
        $node->field_noderef[0]['view']
            <a href="/wire/asset/5">Title</a>

However, there's nothing similar I can iterate through coming from the back-reference nodes... It appears that out of the box, this module is heavily dependent on washing the data through a view, first, which doesn't then pass node id data on to the $node I can pull from in contemplate. Hence:

$node->field_backref_6039a7d891c2aa4a4e (array)
    $node->field_backref_6039a7d891c2aa4a4e[0] (array)
        $node->field_backref_6039a7d891c2aa4a4e[0]['view']
            <dd><div class="view view-noderelationship...[more view-generated code]

Put another way, how could I also get $node->field_backref_6039a7d891c2aa4a4e[0]['nid'] and possibly also ['title']? In the above example?

The goal is to basically combine the outgoing node ref ID's and the incoming back-reference ID's, remove duplicates, and present them all in a "related content" list of nodes. The directionality of the references is inconsequential for my application. An inbound link from other content is just as "related" in our scenario as an outgoing one.

Comments

I think the easiest way would be to override the template related to the view. Here you'll get access to anything views generates, and then you can format the data the way you wish.

Edit the view and try looking at the Theme: Information panel.

Status:Active» Fixed

I forgot to mention a couple more possible options:

2) You can override the theme function used by the back references field formatter.
3) You can create a separate module that implements a new formatter for back references fields, and the you can choose this formatter in "Display fields" screen wherever you need this particular feature.

It seems to me 3) is actually the most powerfull method. To create your own formatter, all you need to do is implement hook_field_formatter_info() for fields of type noderelationships_backref, then implement hook_theme() and provide a theme function for your formatter. Look at the CCK Formatters module for examples on how to extend formatters for other CCK fields.

The builtin formatters are implemented in noderelationships.pages.inc, functions theme_noderelationships_formatter_default() and theme_noderelationships_formatter_count(). Here you have a lot of context information to do whatever you need.

Thanks very much for the very informative reply. In the short term, I used combination of view themes (stripping out much of the default-generated HTML) and minor hacking of the theme inside noderelationships.pages.inc to same effect to get a plain string of nid's, which are then spun through trim(), etc. and stuck in an array. Your fix actually sounds like it's along the same logical lines, though much cleaner in that it doesn't require hacking a piece of existing module code. Glad I was at least looking in the right direction.

Cheers!

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.