1 node.pages.inc | node_preview($node_tempstore_id, $node_type) |
Generates a node preview.
@since 1.0.6 Function removed (see: https://github.com/backdrop/backdrop-issues/issues/218). @since 1.11.0 Function re-added (see: https://github.com/backdrop/backdrop-issues/issues/3062).
Parameters
$node_tempstore_id: The tempstore ID of the node being previewed.
$node_type: The node type of the node being previewed.
Return value
An HTML-formatted string of a node preview.:
See also
File
- core/
modules/ node/ node.pages.inc, line 593 - Callbacks for adding, editing, and deleting content and managing revisions.
Code
function node_preview($node_tempstore_id, $node_type) {
// The tempstore object may have expired or an invalid ID submitted. Use the
// node object if available, otherwise return to the node edit page.
if (!$node = node_get_node_tempstore($node_tempstore_id)) {
backdrop_set_message(t('The preview ID is invalid or the stored preview has expired.'), 'error');
backdrop_goto('node/add/' . $node_type);
}
// Set status to true so we don't get the 'unpublished' CSS.
$node->status = TRUE;
_field_invoke_multiple('load', 'node', array($node->nid => $node));
// Load the author'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;
}
else {
$node->uid = 0;
}
}
elseif ($node->uid) {
$user = user_load($node->uid);
$node->name = $user->name;
}
$node->changed = REQUEST_TIME;
// Get the view mode to render the preview in.
$view_mode = empty($_GET['view_mode']) ? 'full' : $_GET['view_mode'];
// Property so we can manipulate $page in template_preprocess_node.
if ($view_mode == 'full' || $view_mode == 'default') {
backdrop_set_title($node->title);
$node->in_preview = TRUE;
}
$build = array();
$build['#attached']['js'][] = backdrop_get_path('module', 'node') . '/js/node.preview.js';
$build['#attached']['css'][] = backdrop_get_path('module', 'node') . '/css/node.preview.css';
$build['preview_form_select'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array('node-preview-container', 'container-inline')
),
);
$form = backdrop_get_form('node_preview_banner_form', $node, $node_tempstore_id);
$build['preview_form_select']['view-mode'] = $form;
$build['preview'] = node_view($node, $view_mode);
$build['#theme'] = 'node_preview';
return $build;
}