Hi,

I have a content type which has a nodereference field that is being displayed via cck_blocks. So I'm able to create self-references. When referencing any other node, the CCK Block displays it as a Teaser, which is what I told it to do. Self-referencing nodes are however being displayed as Title (link), which is actually not that correct ;)
I stepped through the code (not entirely, sorry) and it seems that the formatter is being rewritten from "teaser" to "default" somewhere inside nodereference.

I modified theme_nodereference_formatter_default() to the following to get a bit of an insight:

/**
 * Theme function for 'default' nodereference field formatter.
 */
function theme_nodereference_formatter_default($element) {
  $output = '';
  if (!empty($element['#item']['nid']) && is_numeric($element['#item']['nid']) && ($title = _nodereference_titles($element['#item']['nid']))) {
    $output = l($title, 'node/'. $element['#item']['nid']);
  }
  
  // I added this:
  foreach(debug_backtrace() as $entry)
  {
    echo "\n -> ".$entry["function"];
    foreach($entry['args'] as $arg)
    {
      if(is_array($arg) && isset($arg['#formatter']))
      {
        echo " (".$arg['#formatter'].")";
      }
    }
  }
  //
  
  return $output;
}

The output is:

 -> theme_nodereference_formatter_default (default)
 -> call_user_func_array
 -> theme (default)
 -> drupal_render (default)
 -> drupal_render
 -> drupal_render
 -> drupal_render
 -> drupal_render
 -> node_view
 -> node_show
 -> node_page_view
 -> call_user_func_array
 -> menu_execute_active_handler
 -> theme_nodereference_formatter_default (teaser)
 -> call_user_func_array
 -> theme (teaser)
 -> theme_nodereference_formatter_full_teaser (teaser)
 -> call_user_func_array
 -> theme (teaser)
 -> content_format
 -> call_user_func_array
 -> module_invoke
 -> cck_blocks_block
 -> call_user_func_array
 -> module_invoke
 -> block_list
 -> theme_blocks
 -> call_user_func_array
 -> theme
 -> template_preprocess_page
 -> call_user_func_array
 -> theme

Best regards,
Lars

CommentFileSizeAuthor
#7 node_reference_self_reference.png14.68 KBAnonymous (not verified)

Comments

lgierth’s picture

I'm sorry I forgot that, my Drupal version is 6.12.

markus_petrux’s picture

Project: Content Construction Kit (CCK) » CCK Blocks
Version: 6.x-2.3 » 6.x-1.x-dev
Component: nodereference.module » Code

This is probably an issue with the CCK Blocks module.

Anonymous’s picture

What's the status of this issue? Please try the newest -dev release.

lgierth’s picture

Hi,

the problem still exists, I tried HEAD with drupal-6.14 and cck-2.5. Here's what I exactly did.

  • Create a new node type
  • Create a node reference field with autocompletion (autocomplete_widgets), which can only reference the node type created before
  • Create a new node of that type and save it
  • Change the node's node reference field so that it references itself
  • Enable the CCK Block for that field
  • Change the field's view to "teaser"

Let me know if you know need more information.

Best regards,
Lars

Anonymous’s picture

Can you post a link where I can see that behaviour?

Anonymous’s picture

Project: CCK Blocks » Content Construction Kit (CCK)
Version: 6.x-1.x-dev » 6.x-2.5
Component: Code » nodereference.module

This is not a cck_blocks issue, as the behaviour is the same, if you display the node reference / self reference with the node itself. CCk blocks only displays the fields how they are renderend by cck.

Anonymous’s picture

StatusFileSize
new14.68 KB

Sorry, forgot the screenshot.

markus_petrux’s picture

Status: Active » Postponed (maintainer needs more info)

What's the problem exactly?

lgierth’s picture

Hi markus_petrux,

a nodereference field, whose value's nid and parent nid are the same will not display correctly.

I just noticed that this might be a mechanism to prevent the creation of infinite loops (a node displays itself displays itself displays itself, etc.).

Best regards,
Lars

markus_petrux’s picture

Category: bug » support
Status: Postponed (maintainer needs more info) » Fixed

Oh, I see. Well, yes there's such a check in the formatter of the nodereference field.

I think the current code is safe enough, so I would suggest overriding the theme function and here you can adapt the check to your own needs. See theme_nodereference_formatter_full_teaser() in nodereference.module.

lgierth’s picture

Thanks!

Status: Fixed » Closed (fixed)

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