diff --git a/node_embed.module b/node_embed.module index 1985f63..88eadb6 100644 --- a/node_embed.module +++ b/node_embed.module @@ -107,13 +107,24 @@ function _node_embed_replacements($matches) { /** * Helper function for returning feedback to the user. */ -function _node_embed_user_feedback(stdClass $parent_node, $matches, $type) { - // There is no point to show the embed code if the user can't edit the node. - if (!node_access('update', $parent_node)) { - return ''; +function _node_embed_user_feedback($parent_node, $matches, $type) { + if (is_object($parent_node)) { + // There is no point to show the embed code if the user can't edit the node. + if (!node_access('update', $parent_node)) { + return ''; + } + + $parent_node_url = l($parent_node->title, 'node/' . $parent_node->nid); } + else { + // There is no point to show the embed code if the user can't edit any node. + if (!user_access('administer nodes')) { + return ''; + } - $parent_node_url = l($parent_node->title, 'node/' . $parent_node->nid); + // There is no Parent. + $type = null; + } switch ($type) { case 'access' : @@ -130,9 +141,9 @@ function _node_embed_user_feedback(stdClass $parent_node, $matches, $type) { break; case 'loop' : drupal_set_message(t('Loop detected while embedding code %code in !node', array( - '%code' => $matches[0], - '!node' => $parent_node_url, - )), 'error'); + '%code' => $matches[0], + '!node' => $parent_node_url, + )), 'error'); break; case 'invalid' : drupal_set_message(t('The embedded node ID %nid in !node does not exist (anymore).', array( @@ -140,9 +151,14 @@ function _node_embed_user_feedback(stdClass $parent_node, $matches, $type) { '!node' => $parent_node_url, )), 'warning'); break; + default : + drupal_set_message(t('There is a node with embedded node ID %nid that does not exist (anymore).', array( + '%nid' => $matches[1], + )), 'warning'); } - return $matches[0]; + // Return a simple inline message for content editors to identify the problem. + return t('-- Failed to embed node %nid. --', array('%nid' => $matches[1])); } /**