You are here

function pagepreview_node_form_build_preview in Page Preview 6

Same name and namespace in other branches
  1. 7 pagepreview.module \pagepreview_node_form_build_preview()

Alternate submit callback for the node form "Preview" button.

1 string reference to 'pagepreview_node_form_build_preview'
pagepreview_form_alter in ./pagepreview.module
Implements hook_form_alter().

File

./pagepreview.module, line 40
An alternative node previewing system for the node add/edit form.

Code

function pagepreview_node_form_build_preview($form, &$form_state) {
  $node = node_form_submit_build_node($form, $form_state);
  $node->pagepreview = TRUE;

  // Get the expected URL alias from Pathauto, if applicable.
  if (module_exists('pathauto') && (!isset($node->pathauto_perform_alias) || $node->pathauto_perform_alias)) {
    _pathauto_include();
    $placeholders = pathauto_get_placeholders('node', $node);
    $src = "node/" . $node->nid;
    $alias = pathauto_create_alias('node', 'return', $placeholders, $src, $node->nid, $node->type, $node->language);
    if ($alias) {
      $node->path = $alias;
    }
  }

  // Cache the temporary node and active the preview area of the node form.
  cache_set('pagepreview:' . $form['form_token']['#default_value'], $node, 'cache_page', CACHE_TEMPORARY);
  $form_state['node_preview'] = '<iframe class="pagepreview-preview" style="width:100%; height: 480px;" src="' . base_path() . 'pagepreview/' . $form['#token'] . '"></iframe>';
  drupal_set_title(t('Preview'));
}