node_preview

Versions
4.6 – 7
node_preview($node)

Generate a node preview, including a form for further edits.

▾ 1 function calls node_preview()

node_page in modules/node.module
Menu callback; dispatches control to the appropriate operation handler.

Code

modules/node.module, line 1487

<?php
function node_preview($node) {
  // Convert the array to an object:
  $node = array2object($node);

  if (node_access('create', $node) || node_access('update', $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(array('name' => $node->name))) {
        $node->uid = $user->uid;
      }
      else {
        $node->uid = 0; // anonymous user
      }
    }
    else if ($node->uid) {
      $user = user_load(array('uid' => $node->uid));
      $node->name = $user->name;
    }

    // Set the created time when needed:
    if (empty($node->created)) {
      $node->created = time();
    }

    // Extract a teaser, if it hasn't been set (e.g. by a module-provided
    // 'teaser' form item).
    if (!isset($node->teaser)) {
      $node->teaser = node_teaser($node->body, $node->format);
    }

    // Display a preview of the node:
    // Previewing alters $node so it needs to be cloned.
    if (!form_get_errors()) {
      $output = theme('node_preview', clone($node));
    }

    $output .= node_form($node);

    $name = node_invoke($node, 'node_name');
    drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('create content'), 'node/add'), l(t('Submit %name', array('%name' => $name)), 'node/add/'. $node->type)));

    return $output;
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.