From 1e4c4c3f82cfebcd0839f4d8615a6f76b1bfaba2 Mon Sep 17 00:00:00 2001 From: webchick <drupal@webchick.net> Date: Mon, 5 Oct 2015 10:08:32 -0700 Subject: [PATCH] Issue #2579615 by longwave, dawehner, juxe, alexpott: Views only able to add Attachment display --- core/modules/views_ui/admin.inc | 2 +- .../views_ui/src/Tests/DisplayTest.php | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/core/modules/views_ui/admin.inc b/core/modules/views_ui/admin.inc index 1187be5e813e..6170ed4f846a 100644 --- a/core/modules/views_ui/admin.inc +++ b/core/modules/views_ui/admin.inc @@ -315,7 +315,7 @@ function views_ui_build_form_url(FormStateInterface $form_state) { function views_ui_form_button_was_clicked($element, FormStateInterface $form_state) { $user_input = $form_state->getUserInput(); $process_input = empty($element['#disabled']) && ($form_state->isProgrammed() || ($form_state->isProcessingInput() && (!isset($element['#access']) || $element['#access']))); - if ($process_input && !$form_state->getTriggeringElement() && !empty($element['#is_button']) && isset($user_input[$element['#name']]) && isset($element['#values']) && in_array($user_input[$element['#name']], $element['#values'], TRUE)) { + if ($process_input && !$form_state->getTriggeringElement() && !empty($element['#is_button']) && isset($user_input[$element['#name']]) && isset($element['#values']) && in_array($user_input[$element['#name']], array_map('strval', $element['#values']), TRUE)) { $form_state->setTriggeringElement($element); } return $element; diff --git a/core/modules/views_ui/src/Tests/DisplayTest.php b/core/modules/views_ui/src/Tests/DisplayTest.php index ff7ca81f2873..4fab7d893f72 100644 --- a/core/modules/views_ui/src/Tests/DisplayTest.php +++ b/core/modules/views_ui/src/Tests/DisplayTest.php @@ -34,6 +34,26 @@ class DisplayTest extends UITestBase { */ public static $modules = array('contextual'); + /** + * Tests adding a display. + */ + public function testAddDisplay() { + $view = $this->randomView(); + $this->assertNoText('Block'); + $this->assertNoText('Block 2'); + + $this->drupalPostForm(NULL, [], t('Add @display', ['@display' => 'Block'])); + $this->assertText('Block'); + $this->assertNoText('Block 2'); + + // Views has special form handling in views_ui_form_button_was_clicked() + // to be able to change the submit button text via JS, this simulates what + // the JS is doing. + $this->drupalPostForm(NULL, [], NULL, [], [], NULL, '&op=Block'); + $this->assertText('Block'); + $this->assertText('Block 2'); + } + /** * Tests reordering of displays. */ -- GitLab