function node_preview

7.x node.pages.inc node_preview($node)
6.x node.pages.inc 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

node_form_build_preview()

1 call to node_preview()
node_form_build_preview in drupal-7.x/modules/node/node.pages.inc
Form submission handler for node_form().
5 string references to 'node_preview'
node_form in drupal-7.x/modules/node/node.pages.inc
Form constructor for the node add/edit form.
node_form_build_preview in drupal-7.x/modules/node/node.pages.inc
Form submission handler for node_form().
node_theme in drupal-7.x/modules/node/node.module
Implements hook_theme().
node_type_form in drupal-7.x/modules/node/content_types.inc
Form constructor for the node type editing form.
node_update_7004 in drupal-7.x/modules/node/node.install
Extend the existing default preview and teaser settings to all node types.

File

drupal-7.x/modules/node/node.pages.inc, line 373
Page callbacks for adding, editing, deleting, and revisions management for content.

Code

function node_preview($node) {
  if (node_access('create', $node) || node_access('update', $node)) {
    _field_invoke_multiple('load', 'node', array($node->nid => $node));
    // Load the user's name when needed.
    if (isset($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($node->name)) {
        $node->uid = $user->uid;
        $node->picture = $user->picture;
      }
      else {
        $node->uid = 0; // anonymous user
      }
    }
    elseif ($node->uid) {
      $user = user_load($node->uid);
      $node->name = $user->name;
      $node->picture = $user->picture;
    }

    $node->changed = REQUEST_TIME;
    $nodes = array($node->nid => $node);
    field_attach_prepare_view('node', $nodes, 'full');

    // Display a preview of the node.
    if (!form_get_errors()) {
      $node->in_preview = TRUE;
      $output = theme('node_preview', array('node' => $node));
      unset($node->in_preview);
    }
    drupal_set_title(t('Preview'), PASS_THROUGH);

    return $output;
  }
}