diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterFormatAccessTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterFormatAccessTest.php index 6daa1d4..f2aae1b 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterFormatAccessTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterFormatAccessTest.php @@ -225,7 +225,7 @@ function testFormatWidgetPermissions() { $this->assertText($edit[$body_value_key], 'Old body found in preview.'); // Save and verify that only the title was changed. - $this->drupalPost('node/' . $node->nid . '/edit', $new_edit, t('Preview'), array('query' => array('tempstore_id' => $node->uuid))); + $this->drupalPost('node/' . $node->nid . '/edit', $new_edit, t('Save')); $this->assertNoText($edit['title'], 'Old title not found.'); $this->assertText($new_edit['title'], 'New title found.'); $this->assertText($edit[$body_value_key], 'Old body found.'); diff --git a/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php b/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php index 77575c1..532e1e3 100644 --- a/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php @@ -45,10 +45,11 @@ function testPagePreview() { $this->assertText($edit[$title_key], 'Title displayed.'); $this->assertText($edit[$body_key], 'Body displayed.'); - // Check that the title and body fields are displayed with the correct values - // after going back to the content edit page. + // Check that the title and body fields are displayed with the correct + // values after going back to the content edit page. $url = parse_url($this->getUrl()); - list(, , , $tempstore_id) = explode('/', $url['path']); + $paths = explode('/', $url['path']); + $tempstore_id = array_pop($paths); $options = array('query' => array('tempstore_id' => $tempstore_id)); $this->drupalGet('node/add/page', $options); $this->assertFieldByName($title_key, $edit[$title_key], 'Title field displayed.'); @@ -77,10 +78,11 @@ function testPagePreviewWithRevisions() { $this->assertText($edit[$title_key], 'Title displayed.'); $this->assertText($edit[$body_key], 'Body displayed.'); - // Check that the title and body fields are displayed with the correct values - // after going back to the content edit page. + // Check that the title and body fields are displayed with the correct + // values after going back to the content edit page. $url = parse_url($this->getUrl()); - list(, , , $tempstore_id) = explode('/', $url['path']); + $paths = explode('/', $url['path']); + $tempstore_id = array_pop($paths); $options = array('query' => array('tempstore_id' => $tempstore_id)); $this->drupalGet('node/add/page', $options); $this->assertFieldByName($title_key, $edit[$title_key], 'Title field displayed.'); diff --git a/core/modules/node/node.module b/core/modules/node/node.module index a957c81..4792e19 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1753,11 +1753,11 @@ function node_menu() { 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); - // @todo real access check. $items['node/preview/%node_tempstore'] = array( 'page callback' => 'node_preview', 'page arguments' => array(2), - 'access callback' => TRUE, + 'access callback' => 'node_access_preview', + 'access arguments' => array(2), 'file' => 'node.pages.inc', ); $items['node/%node/edit'] = array( @@ -2299,13 +2299,13 @@ function node_page_build(&$page) { /** * Get the preview form selection box. * - * @param string $bundle - * The name of the node bundle. + * @param Drupal\node\Node $node + * A node entity. * * @return $form * The view mode preview selection form. */ -function node_preview_form_select($form, $form_state, $node) { +function node_preview_form_select($form, $form_state, Node $node) { // Always add default. $view_mode_options = array('default' => t('Full')); @@ -2808,6 +2808,24 @@ function node_node_access($node, $op, $account) { } /** + * Access callback: Checks a user's permission for previewing a node. + * + * @param Drupal\node\Node|string|stdClass $node + * The node entity to be previewed. + * + * @return + * TRUE if the user has access to the preview, FALSE otherwise. + * + * @see node_menu() + */ +function node_access_preview($node) { + if (node_access('create', $node) || node_access('update', $node)) { + return TRUE; + } + return; +} + +/** * Helper function to generate standard node permission list for a given type. * * @param $name diff --git a/core/modules/node/node.pages.inc b/core/modules/node/node.pages.inc index 490f09c..639e264 100644 --- a/core/modules/node/node.pages.inc +++ b/core/modules/node/node.pages.inc @@ -119,54 +119,50 @@ function node_add($node_type) { * @param Drupal\node\Node $node * The node to preview. * - * @return - * An HTML-formatted string of a node preview. + * @return array + * A form array as expected by drupal_render(). */ function node_preview(Node $node) { - // @todo move access check earlier ? - if (node_access('create', $node) || node_access('update', $node)) { - - // Set status to true so we don't get the 'unpublished' css. - $node->status = TRUE; + // 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 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; - } - else { - $node->uid = 0; // anonymous user - } + _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; } - elseif ($node->uid) { - $user = user_load($node->uid); - $node->name = $user->name; + else { + $node->uid = 0; // anonymous user } + } + 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 = drupal_container()->get('request')->query->get('view_mode'); - if (empty($view_mode)) { - $view_mode = 'full'; - } + $node->changed = REQUEST_TIME; - // Property so we can manipulate $page in template_preprocess_node. - if ($view_mode == 'full' || $view_mode == 'default') { - drupal_set_title($node->title); - $node->node_page_title = TRUE; - } + // Get the view mode to render the preview in. + $view_mode = drupal_container()->get('request')->query->get('view_mode'); + if (empty($view_mode)) { + $view_mode = 'full'; + } - $build = array(); - // @todo all links should be disabled, except for returning to the edit form. - $build['#attached']['library'][] = array('node', 'drupal.node.preview'); - $build['preview'] = node_view($node, $view_mode); - return $build; + // Property so we can manipulate $page in template_preprocess_node. + if ($view_mode == 'full' || $view_mode == 'default') { + drupal_set_title($node->title); + $node->node_page_title = TRUE; } + + $build = array(); + // @todo all links should be disabled, except for returning to the edit form. + $build['#attached']['library'][] = array('node', 'drupal.node.preview'); + $build['preview'] = node_view($node, $view_mode); + return $build; } /** diff --git a/core/modules/poll/lib/Drupal/poll/Tests/PollTestBase.php b/core/modules/poll/lib/Drupal/poll/Tests/PollTestBase.php index bfb5387..7721007 100644 --- a/core/modules/poll/lib/Drupal/poll/Tests/PollTestBase.php +++ b/core/modules/poll/lib/Drupal/poll/Tests/PollTestBase.php @@ -74,7 +74,8 @@ function pollCreate($title, $choices, $preview = TRUE) { if ($preview) { $this->drupalPost(NULL, $edit, t('Preview')); $url = parse_url($this->getUrl()); - list(, , , $tempstore_id) = explode('/', $url['path']); + $paths = explode('/', $url['path']); + $tempstore_id = array_pop($paths); $post_url = 'node/add/poll'; $options = array('query' => array('tempstore_id' => $tempstore_id)); $this->drupalGet('node/add/poll', $options);