From 959df8dbc44ccf792bf9be136ce83fe975e76470 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 17 Jan 2017 11:41:00 +0000 Subject: [PATCH] Issue #2834316 by Berdir, claudiu.cristea: Node preview shows and defaults to "Default" instead of "Full" view mode --- core/modules/node/src/Form/NodePreviewForm.php | 4 +++- core/modules/node/src/NodeForm.php | 2 +- core/modules/node/src/Tests/PagePreviewTest.php | 10 +++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/core/modules/node/src/Form/NodePreviewForm.php b/core/modules/node/src/Form/NodePreviewForm.php index c56131f57b..829fee100a 100644 --- a/core/modules/node/src/Form/NodePreviewForm.php +++ b/core/modules/node/src/Form/NodePreviewForm.php @@ -85,9 +85,11 @@ public function buildForm(array $form, FormStateInterface $form_state, EntityInt '#options' => array('attributes' => array('class' => array('node-preview-backlink'))) + $query_options, ); - $view_mode_options = $this->entityManager->getViewModeOptionsByBundle('node', $node->bundle()); + // Always show full as an option, even if the display is not enabled. + $view_mode_options = ['full' => $this->t('Full')] + $this->entityManager->getViewModeOptionsByBundle('node', $node->bundle()); // Unset view modes that are not used in the front end. + unset($view_mode_options['default']); unset($view_mode_options['rss']); unset($view_mode_options['search_index']); diff --git a/core/modules/node/src/NodeForm.php b/core/modules/node/src/NodeForm.php index 216044ae5a..bb58377d77 100644 --- a/core/modules/node/src/NodeForm.php +++ b/core/modules/node/src/NodeForm.php @@ -265,7 +265,7 @@ public function preview(array $form, FormStateInterface $form_state) { $route_parameters = [ 'node_preview' => $this->entity->uuid(), - 'view_mode_id' => 'default', + 'view_mode_id' => 'full', ]; $options = []; diff --git a/core/modules/node/src/Tests/PagePreviewTest.php b/core/modules/node/src/Tests/PagePreviewTest.php index ab2b90836c..086ae82709 100644 --- a/core/modules/node/src/Tests/PagePreviewTest.php +++ b/core/modules/node/src/Tests/PagePreviewTest.php @@ -196,7 +196,7 @@ function testPagePreview() { ->save(); $view_mode_edit = array('view_mode' => 'teaser'); - $this->drupalPostForm('node/preview/' . $uuid . '/default', $view_mode_edit, t('Switch')); + $this->drupalPostForm('node/preview/' . $uuid . '/full', $view_mode_edit, t('Switch')); $this->assertRaw('view-mode-teaser', 'View mode teaser class found.'); $this->assertNoText($edit[$body_key], 'Body not displayed.'); @@ -298,7 +298,7 @@ function testPagePreview() { // original destination, if set. $destination = 'node'; $this->drupalPostForm($node->toUrl('edit-form'), [], t('Preview'), ['query' => ['destination' => $destination]]); - $parameters = ['node_preview' => $node->uuid(), 'view_mode_id' => 'default']; + $parameters = ['node_preview' => $node->uuid(), 'view_mode_id' => 'full']; $options = ['absolute' => TRUE, 'query' => ['destination' => $destination]]; $this->assertUrl(Url::fromRoute('entity.node.preview', $parameters, $options)); $this->drupalPostForm(NULL, ['view_mode' => 'teaser'], t('Switch')); @@ -308,7 +308,7 @@ function testPagePreview() { // Check that preview page works as expected without a destination set. $this->drupalPostForm($node->toUrl('edit-form'), [], t('Preview')); - $parameters = ['node_preview' => $node->uuid(), 'view_mode_id' => 'default']; + $parameters = ['node_preview' => $node->uuid(), 'view_mode_id' => 'full']; $this->assertUrl(Url::fromRoute('entity.node.preview', $parameters, ['absolute' => TRUE])); $this->drupalPostForm(NULL, ['view_mode' => 'teaser'], t('Switch')); $this->clickLink(t('Back to content editing')); @@ -442,7 +442,7 @@ function testPagePreviewWithRevisions() { /** @var \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver */ $controller_resolver = \Drupal::service('controller_resolver'); $node_preview_controller = $controller_resolver->getControllerFromDefinition('\Drupal\node\Controller\NodePreviewController::view'); - $node_preview_controller($node, 'default'); + $node_preview_controller($node, 'full'); } /** @@ -463,7 +463,7 @@ public function testSimultaneousPreview() { $edit2 = array($title_key => 'Another page title'); $this->drupalPostForm('node/' . $node->id() . '/edit', $edit2, t('Preview')); - $this->assertUrl(\Drupal::url('entity.node.preview', ['node_preview' => $node->uuid(), 'view_mode_id' => 'default'], ['absolute' => TRUE])); + $this->assertUrl(\Drupal::url('entity.node.preview', ['node_preview' => $node->uuid(), 'view_mode_id' => 'full'], ['absolute' => TRUE])); $this->assertText($edit2[$title_key]); } -- GitLab