From 26ae527f293f200229bfca5608e2329a79198e27 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 3 Jan 2017 13:06:01 +0000 Subject: [PATCH] Revert "Issue #2325463 by claudiu.cristea, swentel, GroovyCarrot, bircher, aloknarwaria, lokapujya, Berdir, mohit_aghera, yanniboi, mgifford, BarisW, Yogesh Pawar: Destination URL breaks preview" This reverts commit c7da19c9c38f0faeac24a63ab25fdda17b8b3db6. --- .../modules/node/src/Form/NodePreviewForm.php | 17 ++----------- core/modules/node/src/NodeForm.php | 22 +++++++---------- .../node/src/Tests/PagePreviewTest.php | 24 ------------------- 3 files changed, 11 insertions(+), 52 deletions(-) diff --git a/core/modules/node/src/Form/NodePreviewForm.php b/core/modules/node/src/Form/NodePreviewForm.php index c56131f57b1..8a4cce9339c 100644 --- a/core/modules/node/src/Form/NodePreviewForm.php +++ b/core/modules/node/src/Form/NodePreviewForm.php @@ -73,11 +73,6 @@ class NodePreviewForm extends FormBase { $view_mode = $node->preview_view_mode; $query_options = array('query' => array('uuid' => $node->uuid())); - $query = $this->getRequest()->query; - if ($query->has('destination')) { - $query_options['query']['destination'] = $query->get('destination'); - } - $form['backlink'] = array( '#type' => 'link', '#title' => $this->t('Back to content editing'), @@ -121,18 +116,10 @@ class NodePreviewForm extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $route_parameters = [ + $form_state->setRedirect('entity.node.preview', array( 'node_preview' => $form_state->getValue('uuid'), 'view_mode_id' => $form_state->getValue('view_mode'), - ]; - - $options = []; - $query = $this->getRequest()->query; - if ($query->has('destination')) { - $options['query']['destination'] = $query->get('destination'); - $query->remove('destination'); - } - $form_state->setRedirect('entity.node.preview', $route_parameters, $options); + )); } } diff --git a/core/modules/node/src/NodeForm.php b/core/modules/node/src/NodeForm.php index 216044ae5a6..3a9ed543206 100644 --- a/core/modules/node/src/NodeForm.php +++ b/core/modules/node/src/NodeForm.php @@ -22,6 +22,11 @@ class NodeForm extends ContentEntityForm { */ protected $tempStoreFactory; + /** + * Whether this node has been previewed or not. + */ + protected $hasBeenPreviewed = FALSE; + /** * Constructs a NodeForm object. * @@ -79,7 +84,7 @@ class NodeForm extends ContentEntityForm { $this->entity = $preview->getFormObject()->getEntity(); $this->entity->in_preview = NULL; - $form_state->set('has_been_previewed', TRUE); + $this->hasBeenPreviewed = TRUE; } /** @var \Drupal\node\NodeInterface $node */ @@ -181,7 +186,7 @@ class NodeForm extends ContentEntityForm { $node = $this->entity; $preview_mode = $node->type->entity->getPreviewMode(); - $element['submit']['#access'] = $preview_mode != DRUPAL_REQUIRED || $form_state->get('has_been_previewed'); + $element['submit']['#access'] = $preview_mode != DRUPAL_REQUIRED || $this->hasBeenPreviewed; // If saving is an option, privileged users get dedicated form submit // buttons to adjust the publishing status while saving in one go. @@ -262,19 +267,10 @@ class NodeForm extends ContentEntityForm { $store = $this->tempStoreFactory->get('node_preview'); $this->entity->in_preview = TRUE; $store->set($this->entity->uuid(), $form_state); - - $route_parameters = [ + $form_state->setRedirect('entity.node.preview', array( 'node_preview' => $this->entity->uuid(), 'view_mode_id' => 'default', - ]; - - $options = []; - $query = $this->getRequest()->query; - if ($query->has('destination')) { - $options['query']['destination'] = $query->get('destination'); - $query->remove('destination'); - } - $form_state->setRedirect('entity.node.preview', $route_parameters, $options); + )); } /** diff --git a/core/modules/node/src/Tests/PagePreviewTest.php b/core/modules/node/src/Tests/PagePreviewTest.php index ab2b90836c0..2afcc8d2df7 100644 --- a/core/modules/node/src/Tests/PagePreviewTest.php +++ b/core/modules/node/src/Tests/PagePreviewTest.php @@ -6,7 +6,6 @@ use Drupal\comment\Tests\CommentTestTrait; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Component\Utility\Unicode; use Drupal\Core\Language\LanguageInterface; -use Drupal\Core\Url; use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; @@ -293,29 +292,6 @@ class PagePreviewTest extends NodeTestBase { $this->clickLink(t('Back to content editing')); $this->assertRaw('edit-submit'); - // Check that destination is remembered when clicking on preview. When going - // back to the edit form and clicking save, we should go back to the - // 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']; - $options = ['absolute' => TRUE, 'query' => ['destination' => $destination]]; - $this->assertUrl(Url::fromRoute('entity.node.preview', $parameters, $options)); - $this->drupalPostForm(NULL, ['view_mode' => 'teaser'], t('Switch')); - $this->clickLink(t('Back to content editing')); - $this->drupalPostForm(NULL, [], t('Save')); - $this->assertUrl($destination); - - // 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']; - $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')); - $this->drupalPostForm(NULL, [], t('Save')); - $this->assertUrl($node->toUrl()); - $this->assertResponse(200); - // Assert multiple items can be added and are not lost when previewing. $test_image_1 = current($this->drupalGetTestFiles('image', 39325)); $edit_image_1['files[field_image_0][]'] = drupal_realpath($test_image_1->uri);