diff --git a/core/modules/node/lib/Drupal/node/NodeFormController.php b/core/modules/node/lib/Drupal/node/NodeFormController.php index e64db93..6debd50 100644 --- a/core/modules/node/lib/Drupal/node/NodeFormController.php +++ b/core/modules/node/lib/Drupal/node/NodeFormController.php @@ -27,6 +27,16 @@ class NodeFormController extends EntityFormController { */ protected function prepareEntity() { $node = $this->entity; + + // Check if we can retrieve a node form from the tempstore. + $tempstore_id = drupal_container()->get('request')->query->get('tempstore_id'); + if ($tempstore_id) { + $node->tempstore_id = $tempstore_id; + } + else { + $node->tempstore_id = $node->uuid; + } + // Set up default values, if required. $node_options = variable_get('node_options_' . $node->type, array('status', 'promote')); // If this is a new node, fill in the default values. @@ -386,12 +396,19 @@ public function submit(array $form, array &$form_state) { * A reference to a keyed array containing the current state of the form. */ public function preview(array $form, array &$form_state) { - // @todo Remove this: we should not have explicit includes in autoloaded - // classes. - module_load_include('inc', 'node', 'node.pages'); - drupal_set_title(t('Preview'), PASS_THROUGH); - $form_state['node_preview'] = node_preview($this->entity); - $form_state['rebuild'] = TRUE; + if (!isset($form_state['#in_preview'])) { + $form_state['#in_preview'] = TRUE; + drupal_container()->get('user.tempstore')->get('nodeform')->set($node->tempstore_id, $form_state); + $form_state['redirect'] = 'node/preview/' . $node->tempstore_id; + } + else { + // @todo Remove this: we should not have explicit includes in autoloaded + // classes. + module_load_include('inc', 'node', 'node.pages'); + drupal_set_title($this->entity->title); + $form_state['node_preview'] = node_preview($this->entity); + $form_state['rebuild'] = TRUE; + } } /** diff --git a/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/Node.php b/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/Node.php index 0791287..10cb635 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/Node.php +++ b/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/Node.php @@ -204,6 +204,13 @@ class Node extends EntityNG implements NodeInterface { public $log; /** + * The node tempstore id. + * + * @var integer + */ + public $tempstore_id; + + /** * Overrides \Drupal\Core\Entity\EntityNG::init(). */ protected function init() { diff --git a/core/modules/node/node.module b/core/modules/node/node.module index fbdf07d..f744ad1 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -899,6 +899,23 @@ function node_load($nid = NULL, $reset = FALSE) { } /** + * Load a node form from the tempstore. + * + * @param int $tempstore_id + * The ID of a tempstore object. + * + * @return array|false + * A full form state array, or FALSE if the id is not found. + */ +function node_tempstore_load($tempstore_id) { + $form_state = drupal_container()->get('user.tempstore')->get('nodeform')->get($tempstore_id); + if ($form_state) { + return $form_state; + } + return FALSE; +} + +/** * Loads a node revision from the database. * * @param int $nid @@ -1054,7 +1071,7 @@ function template_preprocess_node(&$variables) { $uri = $node->uri(); $variables['node_url'] = url($uri['path'], $uri['options']); $variables['label'] = check_plain($node->label()); - $variables['page'] = $variables['view_mode'] == 'full' && node_is_page($node); + $variables['page'] = ($variables['view_mode'] == 'full' && node_is_page($node)) || (!empty($node->node_page_title)); // Helpful $content variable for templates. $variables += array('content' => array()); @@ -1647,6 +1664,13 @@ function node_menu() { 'title' => 'View', 'type' => MENU_DEFAULT_LOCAL_TASK, ); + $items['node/preview/%node_tempstore'] = array( + 'page callback' => 'node_preview_page', + 'page arguments' => array(2), + 'access callback' => 'user_access', + 'access arguments' => array('access content'), + 'file' => 'node.pages.inc', + ); $items['node/%node/edit'] = array( 'title' => 'Edit', 'route_name' => 'node_page_edit', diff --git a/core/modules/node/node.pages.inc b/core/modules/node/node.pages.inc index a731f40..4abe3cd 100644 --- a/core/modules/node/node.pages.inc +++ b/core/modules/node/node.pages.inc @@ -97,6 +97,15 @@ function node_add($node_type) { } /** + * @todo + */ +function node_preview_page($form_state) { + // get entity form with form state that will invoke preview() in the form + // controller since we froze the form state in that state; however preview() + // will now react differently thanks to the added #in_preview in there. +} + +/** * Generates a node preview. * * @param \Drupal\Core\Entity\EntityInterface $node