On this page
function node_preview
node_preview($node)
Generates a node preview.
Parameters
$node: The node to preview.
Return value
An HTML-formatted string of a node preview.
See also
File
- modules/node/node.pages.inc, line 373
- Page callbacks for adding, editing, deleting, and revisions management for content.
Code
function node_preview($node) {
// Clone the node before previewing it to prevent the node itself from being
// modified.
$cloned_node = clone $node;
if (node_access('create', $cloned_node) || node_access('update', $cloned_node)) {
_field_invoke_multiple('load', 'node', array($cloned_node->nid => $cloned_node));
// Load the user's name when needed.
if (isset($cloned_node->name)) {
// The use of isset() is mandatory in the context of user IDs, because
// user ID 0 denotes the anonymous user.
if ($user = user_load_by_name($cloned_node->name)) {
$cloned_node->uid = $user->uid;
$cloned_node->picture = $user->picture;
}
else {
$cloned_node->uid = 0; // anonymous user
}
}
elseif ($cloned_node->uid) {
$user = user_load($cloned_node->uid);
$cloned_node->name = $user->name;
$cloned_node->picture = $user->picture;
}
$cloned_node->changed = REQUEST_TIME;
$nodes = array($cloned_node->nid => $cloned_node);
// Display a preview of the node.
if (!form_get_errors()) {
$cloned_node->in_preview = TRUE;
$output = theme('node_preview', array('node' => $cloned_node));
unset($cloned_node->in_preview);
}
drupal_set_title(t('Preview'), PASS_THROUGH);
return $output;
}
}
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!node!node.pages.inc/function/node_preview/7.x