I had the same issue that was raised here: http://drupal.org/node/1040196 and solved it by writing a small module that defines a new formatter for the node_reference field type. It allows you to select a field to be displayed instead of title, defaulting to title when no data exists in that field.
At the moment it is rather crude, since it selects 'value' with a delta of 0, so it won't work for fields that do not use the 'value' key when storing data and will always return the first value only. Still, it will work in most cases, and it's still a work in progress. Comments and reviews are welcome, especially from those more familiar with drupal.
Comment | File | Size | Author |
---|---|---|---|
custom_field.zip | 1.67 KB | andreicio |
Comments
Comment #1
danielb CreditAttribution: danielb commentedJust my opinion, but if something like this goes in, people are going to want to make this feature bigger and better, rather than use the Views mode approach which already addresses this. Given you've already mentioned some shortcomings, it's going to create more support and maintenance work.
Comment #2
andreicio CreditAttribution: andreicio commentedI'm aware of that, and I'm willing to add features and maintain if there's a real request for it. My problem is that my experience with Drupal is very limited so I wanted some confirmation that at least I'm on the right track.
Another question would be what kind of features would be wanted. I percieve some shortcomings, yes, but this is a fix for a very specific problem - custom field in the node itself, not views - and already has solutions for more complex cases (node render).
Comment #3
danielb CreditAttribution: danielb commentedI don't think you are on the right track. You have attempted to implement part of what Views can do, directly into Node reference, and the efforts would be better spent on maintaining Views integration, which already does this better.
Comment #4
andreicio CreditAttribution: andreicio commentedOk, but I don't understand what would be the normal way of displaying a custom field instead of a title inside a regular node rendering. I know that node_reference has a "rendered node" formatter, and you can create a custom render layout, but as far as I could tell they all include the title.
Comment #5
yched CreditAttribution: yched commented@andreicio : that's because by default, all 'rendered nodes' displays are printed through node.tpl.php, which usually hardcodes the display of the node title - that's why 'title' is not part of the 'fields' that can be configured on the 'Manage display' pages.
Not displaying the title would mean :
- create a dedicated 'view mode' :
either programmatically through hook_entity_info_alter() in a custom module,
or using a contrib module - there was http://drupal.org/project/buildmodes for D6, but AFAIK only http://drupal.org/project/ds does it for D7
- change the theme so that the title is not displayed for this specific view mode :
in node.tpl.php (or by using the preprocessor to add a new template suggestion so that
theme('node')
uses a dedicated template for the view mode)Not exactly trivial. So, while I agree with @danielb that this is doable with the current features, and share his concerns about scope creep, I can see the use case for such a formatter (DISCLAIMER : I'm saying this as someone who does NOT plan to dedicate important time maintaining and enriching the References project during the D7 cycle...)
A couple UI challenges, though :
- the specific field to display would be a setting of the formatter
- once the field is picked, you need to pick the formatter to apply for the corresponding field type
- once the formatter is picked, you need to pick the settings for this formatter.
This 2-level dependency is tricky to handle UI-wise, especially within the constraints of the 'Manage display' form.
Comment #6
dwkitchen CreditAttribution: dwkitchen commentedI am looking for something similar to this, I want to show a description before the link. In this case a cast list linking to the actors profile.
Example output:
Cast
Hamlet: Actor 1
Claudius: Actor 2
with "Actor 1" linking to the Actors profile page.
This could be one way of doing it but if there are any suggestions I would appreciate them.
David
Comment #7
andreicio CreditAttribution: andreicio commented@yched:
What you are suggesting is indeed interesting, only I was aiming much lower. All I wanted was a variant of the basic "Title" (with or without link) formatter included in node_reference that would allow the admin to choose a different field to display. Very basic, very text only. For what you say it'd be easier to use views-panels to include a more complex output based on the reference.
In light of that, and of further exposure to views-panels lately I understand danielb's point of view, and agree that it's not a worthwhile endeavor.
@dwkitchen:
What is your node structure? I assume the cast is a multi-value node_reference in the "play" node? If so, how and where do you store the part played by each actor in the play?
One basic solution I see is to use a field with 2 values: a string and a node_reference, the first storing the part, and the second being the link to the actor node. Try this module: Field collection
Comment #8
dwkitchen CreditAttribution: dwkitchen commented@andreicio "where do you store the part played by each actor" was exactly my problem!
Thanks for the recommendation I think Field collection will do what I am looking for.
Comment #9
pr0g CreditAttribution: pr0g commentedThanks for your module.
I need a link for all the fields.