First off: Back-reference field = awesome sauce ++

Second, it does not appear that back-reference fields are available to views. I just want to render a back-reference field in a view, and this does not appear to be possible. It is likely an easy fix. I will submit a patch in a while, but if anyone wants to beat me to it.....

Thanks!

Comments

markus_petrux’s picture

It was not implemented to reduce complexity to the module while it is possible to render the back references view using content_format() function if you want this anywhere it is not available as-is. You could do it in a view using Views Custom Field.

markus_petrux’s picture

Category:bug» support
Status:Active» Fixed
Lukas von Blarer’s picture

could you reference a post where it is shown how to do this? or just paste the code here?

njbooher’s picture

Here's what I ended up with in a Views Custom Field to display all backreference fields for a node of type 'plant'.

<?php
$node
= node_load($data->nid);

foreach (
content_fields(NULL, 'plant') as $field_name => $field) {
 
  if (
$field['type'] == 'noderelationships_backref') {
   
   
$value = content_format($field, $node->$field_name, 'default', $node);
   
    if (!empty(
$value)) {
      print
"<label>" . $field['widget']['label'] . ":</label>";
      print
$value;
    }
   
  }

}
?>
markus_petrux’s picture

@njbooher: Thank you! I have added a reference to your snippet above from the project page.

markus_petrux’s picture

Title:Back reference field is not exposed to views» How to expose the Back references view field to Views using Views Custom Field
Melissamcewen’s picture

Category:support» feature
Status:Fixed» Active

I think this would be a great feature to have. Views Custom Field is a solution, but not for projects where the policy is not to have code in the database.

markus_petrux’s picture

Status:Active» Postponed

Sorry, I do not have the time to work on this. Though, I'll be happy to review patches, better if someone else can also provide some feedback.

For those who want to try it, I think we need to review the code in noderelationships_field_settings().

Wuekkie’s picture

This module should do the trick: Reverse Node Reference And then you can also pull any field from the referenced node.

Wuekkie’s picture

Nevermind. I see now why this doesn't work. Disregard #9

ice5nake’s picture

Component:Code» Views integration
ice5nake’s picture

Status:Postponed» Active

I'd like to get node_load to work with back references.

I'd also like to be able to call content_format with a formatter other than the default from my Views Custom Field, but I can't figure that one out.

This code works.

<?php
$field_name
= 'field_backref_5ce3ff3dfd76347dde';
$node = node_load($data->node_data_field_venue_field_venue_nid);
print
$value = content_format(content_fields($field_name), $node->$field_name, 'default', $node);
?>

I cloned the noderelationships_backref view into a view called noderelationships_backref_simple and made some changes. Since it's tagged noderelationships_backref that makes it a "Back reference view" (not sure exactly how the guts of that work).

This code does not work.

<?php
$field_name
= 'field_backref_5ce3ff3dfd76347dde';
$node = node_load($data->node_data_field_venue_field_venue_nid);
print
$value = content_format(content_fields($field_name), $node->$field_name, 'noderelationships_backref_simple', $node);
?>

How do I create a custom formatter that I can call from content_format for a noderelationships_backref?

ice5nake’s picture

Category:feature» support

I tried over writing theme_noderelationships_formatter_default with phptemplate_noderelationships_formatter_default with no luck.

markus_petrux’s picture

Category:support» feature
Status:Active» Postponed

@ice5nake: Please do not hijack this issue with non related questions. Use different threads for each issue. Though, here I would suggest using the development forums where there are more chances to get feedback from other developers.

thijsvdanker’s picture

@Melissamcewen:

You can solve that by using a Global:custom text field in the view and pasting the php code in the template file for that field.
Make sure you also load the nid field and you can do something like this:

<?php
$item_nid
= $view->field['nid']->original_value;
$node = node_load($item_nid);

foreach (

content_fields(NULL, 'plant') as $field_name => $field) {
 
  if (
$field['type'] == 'noderelationships_backref') {
  
   
$value = content_format($field, $node->$field_name, 'default', $node);
  
    if (!empty(
$value)) {
      print
"<label>" . $field['widget']['label'] . ":</label>";
      print
$value;
    }
  
  }

}

?>
Melissamcewen’s picture

Thanks, but I'm not supposed to use code in the sql database. I think I ended up going with the nodereference_views module.

liquidcms’s picture

pretty sure the module listed in #9 is what you need here... it is very very cool.. should be core in Views.. :)

doublejosh’s picture

There seems to actually be a field on the child node type, in my case: "field_backref_184aeafbbf55e0e200" labeled: "Back references from CHILD in PARENT".
Don't understand why that wouldn't be usable in views?

ice5nake’s picture

The noderelationships home page recommends the "Reverse Node Reference", http://drupal.org/project/reverse_node_reference, which "Enhances Views with reverse relationships for Node Reference fields."

That sounds promising for Views integration.

doublejosh’s picture

Thanks ice5nake for the definitive module option.

It's differentiation from the other option... #798786: How is this different from nodereferrer? ...seems to point out that it does not duplicate data. It just allows a views relationship. That's what I was worried about, since there is already data being stored on the child.

sdowney2002’s picture

Has anyone who's using the PHP snippet in #4 (http://drupal.org/node/849816#comment-3290920) had trouble with Views pager?
I'm using this snippet in a couple of Views that are almost identical; in one of these, this snippet makes the Views pager disappear.

asb’s picture

Issue summary:View changes

The code from #4 seems not to work in Views 3 on D6. The same goes for the Reverse Node Reference module, and the Nodereferrer module - both are not compatible with Views 3.