To display more than titles with nodereferences, maybe we could leave it to a theme function?

In nodereference_field_view_item(), we have this:
return l($referenced_node->title, 'node/'. $referenced_node->nid)

Instead, maybe we could have something like:
return theme('nodereference', $referenced_node);

$referenced_node being a full node object, the theme could choose to display whatever node data it wants.

If anyone likes this idea, I could roll a patch.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ashtonium’s picture

Personally, I was hoping that this was what nodereference did when I first experimented with it.

yched’s picture

I think it might be useful to pass the type of the node whose node reference field you're viewing, along with the node object itself ?

You might want to theme the referenced nodes differently for diferent content types

(not sure that info is available in nodereference_field_view_item(), though)

KarenS’s picture

We definitely need the content type. I forgot about that one, but if you send the whole node you'll get the type, too.

yched’s picture

Karen : not sure i was clear

I meant passing to the theme function the type of the node having the reference (left side of the 'relation'), along with the referenced node itself (right side)

maybe that is what you understood...
I have a hint that we might need to define a vocabulary here :-)

KarenS’s picture

Aha, no I did not understand you. It sure is confusing keeping 'referenced' and 'referenced by' nodes straight. Yes, I agree that the content type of both needs to go to the theme because it could make a difference in how the data should be presented.

David Lesieur’s picture

Good idea! We could pass the $field to the theme function. It has a 'type_name' member which is the type of the node containing the field.

David Lesieur’s picture

Status: Active » Needs review
FileSize
717 bytes

Here's the small patch. If this gets committed, I'll update the patch in http://drupal.org/node/60756.

David Lesieur’s picture

Title: Show more than node titles with nodereference » Theming nodereferences
StevenSokulski’s picture

Category: feature » support

I'm a bit lost in terms of how to implement this. Could somebody throw together a quick step-by-step on how to make this thing work. I've already got the patch in place but unsure how to use it.

David Lesieur’s picture

Category: support » feature

Please do not hijack feature requests into support requests. We can never get the thing committed if it is filed as a support request.

This patch adds a new theme function. Theme functions can be overridden in your theme. You can find how to do this in the handbook. See here and there.

sun’s picture

I've been working on this feature, too. IMHO it doesn't make sense to only theme a referenced node. Each content type needs its own styling. I'd like to propose a new option for each node reference to select whether the referenced node should only be listed (default) or completely loaded into the cck node object.

This was the solution for me. It could be extended to select which fields of the referenced node type should be loaded in the future.

Attached patch integrates this option into nodereferences.module which needs a slightly customization of content.module.

sun’s picture

Sorry, don't have enough time now - this reworked patch includes the patch for nodereference backlinks (node referrers).
It loads the referenced node object always, since this would be done twice otherwise.

alex_b’s picture

This small patch makes use of hook_field_formatter().

It allows you to chose on the Display fields tab wether you want to reference a node by showing the plain title, the linked title, the node teaser or the node body.

You can chose different presentation types for the teaser and the body view of the embedding node. E. g. you can show the teaser of the embedded node in the teaser view of the embedding node and you can show the full node view of the embedded node on the full node view of the embedding node.

It also passes the $field variable to the theming layer, which opens additional theming options on embedded nodes in node.tpl.php.

I rolled this patch against the latest DRUPAL-5 version of nodereference.module (r1.39.2.12).

alex

appel’s picture

Subscribing.

mcreature’s picture

Subscribing.

sun’s picture

Patch in #13 looks solid and clean to me. If that one works, I'd go for that - didn't have the time to test yet.

yched’s picture

Looks ok - the only thing that bugs me is the $referenced_node->field = $field; part - not exaclty sure why, but I'm kind of reluctant... I'll try to give it a closer look.

yched’s picture

Also look http://drupal.org/node/91792 for a more general discussion about this - views output is definitely the way to go, but the implementation is still not resolved.

guardian’s picture

subscribing

ktnk’s picture

Priority: Normal » Critical

Hi,

In order to finalize my site structure, I need to try out the patch above (http://drupal.org/node/65133#comment-191144)

Will it work with my current version of nodereference.module,v 1.39.2.17 2007/03/05 ?

Will this patch be updated for the the latest release? Rolled in to the next cck release?

Should I just replace my nodereference.module file with your patch and run update.php?

Please answer asap,
thanks,
ktnk.

alex_b’s picture

ktnk,

Is actually an interesting question wether the patch in #13 is still applicable - give it a go:

http://drupal.org/patch/apply

yched’s picture

Status: Needs review » Fixed

I committed a slightly reworked version of #13.
It adds both 'referencing_node' and 'referencing_field' properties to the referenced node before rendering. Not sure where we should document this feature, though.

Anonymous’s picture

Status: Fixed » Closed (fixed)