From 453e37235164218f9e374098bb4650d928b65fd2 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 9 Aug 2022 19:46:29 +0100 Subject: [PATCH] Issue #2313073 by smustgrave, asad_ahmed, mrinalini9, Munavijayalakshmi, Abhijith S, Lendude, alexpott: Views preview doesn't pass 0 to context filters (cherry picked from commit 43ea903a4054935e9d0aa51438f7850857b54e0b) --- core/modules/views_ui/src/ViewPreviewForm.php | 4 ++-- .../views_ui/tests/src/Functional/PreviewTest.php | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/core/modules/views_ui/src/ViewPreviewForm.php b/core/modules/views_ui/src/ViewPreviewForm.php index 1e5a2a66320..82f93ee79af 100644 --- a/core/modules/views_ui/src/ViewPreviewForm.php +++ b/core/modules/views_ui/src/ViewPreviewForm.php @@ -40,7 +40,7 @@ class ViewPreviewForm extends ViewFormBase { '#default_value' => \Drupal::config('views.settings')->get('ui.always_live_preview'), ]; - // Add the arguments textfield + // Add the arguments textfield. $form['controls']['view_args'] = [ '#type' => 'textfield', '#title' => $this->t('Preview with contextual filters:'), @@ -49,7 +49,7 @@ class ViewPreviewForm extends ViewFormBase { ]; $args = []; - if (!$form_state->isValueEmpty('view_args')) { + if ($form_state->getValue('view_args', '') !== '') { $args = explode('/', $form_state->getValue('view_args')); } diff --git a/core/modules/views_ui/tests/src/Functional/PreviewTest.php b/core/modules/views_ui/tests/src/Functional/PreviewTest.php index f5a9f540e36..5f941da222c 100644 --- a/core/modules/views_ui/tests/src/Functional/PreviewTest.php +++ b/core/modules/views_ui/tests/src/Functional/PreviewTest.php @@ -39,7 +39,15 @@ class PreviewTest extends UITestBase { ]); $this->assertSession()->elementsCount('xpath', $selector, 1); - $this->submitForm($edit = ['view_args' => '100'], 'Update preview'); + $this->submitForm(['view_args' => '100'], 'Update preview'); + + // Test that area text and exposed filters are present and rendered. + $this->assertSession()->fieldExists('id'); + $this->assertSession()->pageTextContains('Test header text'); + $this->assertSession()->pageTextContains('Test footer text'); + $this->assertSession()->pageTextContains('Test empty text'); + + $this->submitForm(['view_args' => '0'], 'Update preview'); // Test that area text and exposed filters are present and rendered. $this->assertSession()->fieldExists('id');