Problem/Motivation

If I embed a node that is scheduled to be unpublished on a certain date, once the node is unpublished the unrendered token text appears on the page. For example:

[[nid:1336]]

That appears on the live site, which looks very out of place.

The code that returns this is from this function in node_embed.module:

function _node_make_replacements($matches) {

  $node = node_load($matches[1]);
  
  if ($node == FALSE || !node_access('view', $node) || !$node->status) {
    
    return "[[nid:{$matches[1]}]]";

  } // if
  else {

While I'm particularly concerned about how a node embed looks once the node is unpublished, the same could possible be true if somebody doesn't have access to the node.

Proposed resolution

The simplest way to not return the token to the user would be to just change this to:

function _node_make_replacements($matches) {

  $node = node_load($matches[1]);
  
  if ($node == FALSE || !node_access('view', $node) || !$node->status) {
    
    return "";

  } // if
  else {

There might be some legitimate reasons why it would be good to return the unrendered token to the user that I'm not aware of, though, so maybe this should be configurable? It would be nice if this could be configured per role so that admin could see unpublished node tokens, while anonymous users or users without proper permissions wouldn't see the token.

It's entirely possible I'm missing something, and there's a better way to handle this.

Remaining tasks

Decide if this is an actual bug, or if I'm missing something. If this does look like a legitimate problem, decide if display should be based per role or maybe a configuration setting.

User interface changes

Unpublished node tokens would no longer be visible, or possibly would only be visible to those with certain permissions.

API changes

Possibly adding an additional permission to view tokens for unpublished node embeds.

Comments

sreynen’s picture

The code suggests this was intentional, but I'm fairly sure whoever wrote it is no longer around, so we'll have to go with how we think it should work now. I think it makes sense to restrict visibility of failed tokens based on a permission. That permission should probably default to all users (anonymous + authenticated) to avoid surprises on existing installs, while still allowing sites to hide the tokens if desired.

MrHaroldA’s picture

Assigned: Unassigned » MrHaroldA
Category: Feature request » Bug report
Priority: Normal » Major

Yeah, this is rather ugly. Have to think about what the correct behavior should be, which probably doesn't include a $node->status check.

olli’s picture

I couldn't reproduce this with latest dev. Was this fixed by #2389893: Endless loop with circular node-embedding dependency?