Hi there,
we use a contenttype "video" that references other "videos". The display of the a node "video" contains its data and teaser-views of the referenced nodes. when you unpublish a referenced video, it's still shown (but its link leads to an "you don't have access.." page). Can I somehow prevent unpublished nodes from being shown for anonymous users- i would expect this "normal" behaviour? I know I could do it by manually checking the published-status in a template, but is there another solution?
Regards Tom

Comments

dawehner’s picture

its the normal behaviour to show the nodes, wether they are published or not.

but you can theme the formatters and check whether the content is published, or better whether the current user has access to the node via node_access

Therefore you would have to override:
theme_nodereference_formatter_default
theme_nodereference_formatter_plain
or
theme_nodereference_formatter_full_teaser

depend on which formatter you want to use

thommyboy’s picture

thanks- i would have expected "normal" behaviour to check for published but sure it can be solved the way you described...

karens’s picture

Status: Active » Fixed

You should also be able to add a relationship to the referenced node and then add a published=true filter for the related node.

thommyboy’s picture

thanks karenS, that's a good idea!

kforge’s picture

Use the Contemplate module. Click the template tab to edit your node type. For example, if I created one CCK nodeaccess field called "field_nodereference", it would appear in the body template as something like $node->field_nodereference[0]['view']. Find this field item in the body template, and wrap it in a conditional expression:

Existing field item output:

<div class="field field-type-nodereference field-field-nodereference">
  <div class="field-items">
      <div class="field-item"><?php print $node->field_nodereference[0]['view'] ?></div>
  </div>
</div>

Modified output (which will disable the appearance of unpublished nodes):

<?php if(!strpos($node->field_nodereference[0]['view'],"unpublished")>0):?>
<div class="field field-type-nodereference field-field-nodereference">
  <div class="field-items">
      <div class="field-item"><?php print $node->field_nodereference[0]['view'] ?></div>
  </div>
</div>
<?php endif;?>

Status: Fixed » Closed (fixed)

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

remaye’s picture

Sorry to post in this issue about 2 years later,
I tried to use advice at #1 and in my case node references are displayed as full nodes, so I tried to override "theme_nodereference_formatter_full_teaser" and it's not working : "mytheme_nodereference_formatter_full_teaser" is not called.

If I display node references as "title" or "title with link" and override "theme_nodereference_formatter_default" or "theme_nodereference_formatter_plain" this is working well.

I'm not a Drupal expert but I'm suspecting the way hook theme for "nodereference_formatter_full_teaser" is defined does not allow the function to be themable... What do you think ?

Thanks for helping

vegantriathlete’s picture

Status: Closed (fixed) » Closed (duplicate)

Duplicate of node/1183758

vegantriathlete’s picture

Status: Closed (duplicate) » Closed (fixed)

Ooops! I didn't actually need to change the status on the last comment. Placing it back in its previous state.