Skip to content
Snippets Groups Projects
Commit afa7d30c authored by catch's avatar catch
Browse files

Issue #2149751 by damiankloip: Views exposed forms are broken.

parent e8c263c4
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -181,8 +181,19 @@ public function preExecute() { } ...@@ -181,8 +181,19 @@ public function preExecute() { }
public function postExecute() { } public function postExecute() { }
/**
* Alters the view exposed form.
*
* @param $form
* The form build array. Passed by reference.
* @param $form_state
* The form state. Passed by reference.
*/
public function exposedFormAlter(&$form, &$form_state) { public function exposedFormAlter(&$form, &$form_state) {
$form['submit']['#value'] = $this->options['submit_button']; if (!empty($this->options['submit_button'])) {
$form['actions']['submit']['#value'] = $this->options['submit_button'];
}
// Check if there is exposed sorts for this view // Check if there is exposed sorts for this view
$exposed_sorts = array(); $exposed_sorts = array();
foreach ($this->view->sort as $id => $handler) { foreach ($this->view->sort as $id => $handler) {
...@@ -226,7 +237,7 @@ public function exposedFormAlter(&$form, &$form_state) { ...@@ -226,7 +237,7 @@ public function exposedFormAlter(&$form, &$form_state) {
} }
if (!empty($this->options['reset_button'])) { if (!empty($this->options['reset_button'])) {
$form['reset'] = array( $form['actions']['reset'] = array(
'#value' => $this->options['reset_button_label'], '#value' => $this->options['reset_button_label'],
'#type' => 'submit', '#type' => 'submit',
'#weight' => 10, '#weight' => 10,
...@@ -242,7 +253,7 @@ public function exposedFormAlter(&$form, &$form_state) { ...@@ -242,7 +253,7 @@ public function exposedFormAlter(&$form, &$form_state) {
// Set the access to FALSE if there is no exposed input. // Set the access to FALSE if there is no exposed input.
if (!array_intersect_key($all_exposed, $this->view->exposed_input)) { if (!array_intersect_key($all_exposed, $this->view->exposed_input)) {
$form['reset']['#access'] = FALSE; $form['actions']['reset']['#access'] = FALSE;
} }
} }
......
...@@ -21,7 +21,7 @@ class ExposedFormTest extends ViewTestBase { ...@@ -21,7 +21,7 @@ class ExposedFormTest extends ViewTestBase {
* *
* @var array * @var array
*/ */
public static $testViews = array('test_reset_button', 'test_exposed_block'); public static $testViews = array('test_exposed_form_buttons', 'test_exposed_block');
/** /**
* Modules to enable. * Modules to enable.
...@@ -49,34 +49,69 @@ protected function setUp() { ...@@ -49,34 +49,69 @@ protected function setUp() {
} }
} }
/**
* Tests the submit button.
*/
public function testSubmitButton() {
// Test the submit button value defaults to 'Apply'.
$this->drupalGet('test_exposed_form_buttons');
$this->assertResponse(200);
$this->helperButtonHasLabel('edit-submit-test-exposed-form-buttons', t('Apply'));
// Rename the label of the submit button.
$view = Views::getView('test_exposed_form_buttons');
$view->setDisplay();
$exposed_form = $view->display_handler->getOption('exposed_form');
$exposed_form['options']['submit_button'] = $expected_label = $this->randomName();
$view->display_handler->setOption('exposed_form', $exposed_form);
$view->save();
views_invalidate_cache();
// Make sure the submit button label changed.
$this->drupalGet('test_exposed_form_buttons');
$this->helperButtonHasLabel('edit-submit-test-exposed-form-buttons', $expected_label);
// Make sure an empty label uses the default 'Apply' button value too.
$view = Views::getView('test_exposed_form_buttons');
$view->setDisplay();
$exposed_form = $view->display_handler->getOption('exposed_form');
$exposed_form['options']['submit_button'] = '';
$view->display_handler->setOption('exposed_form', $exposed_form);
$view->save();
views_invalidate_cache();
// Make sure the submit button label shows 'Apply'.
$this->drupalGet('test_exposed_form_buttons');
$this->helperButtonHasLabel('edit-submit-test-exposed-form-buttons', t('Apply'));
}
/** /**
* Tests whether the reset button works on an exposed form. * Tests whether the reset button works on an exposed form.
*/ */
public function testResetButton() { public function testResetButton() {
// Test the button is hidden when there is no exposed input. // Test the button is hidden when there is no exposed input.
$this->drupalGet('test_reset_button'); $this->drupalGet('test_exposed_form_buttons');
$this->assertNoField('edit-reset'); $this->assertNoField('edit-reset');
$this->drupalGet('test_reset_button', array('query' => array('type' => 'article'))); $this->drupalGet('test_exposed_form_buttons', array('query' => array('type' => 'article')));
// Test that the type has been set. // Test that the type has been set.
$this->assertFieldById('edit-type', 'article', 'Article type filter set.'); $this->assertFieldById('edit-type', 'article', 'Article type filter set.');
// Test the reset works. // Test the reset works.
$this->drupalGet('test_reset_button', array('query' => array('op' => 'Reset'))); $this->drupalGet('test_exposed_form_buttons', array('query' => array('op' => 'Reset')));
$this->assertResponse(200); $this->assertResponse(200);
// Test the type has been reset. // Test the type has been reset.
$this->assertFieldById('edit-type', 'All', 'Article type filter has been reset.'); $this->assertFieldById('edit-type', 'All', 'Article type filter has been reset.');
// Test the button is hidden after reset. // Test the button is hidden after reset.
$this->assertNoField('edit-reset'); $this->assertNoField('edit-reset');
}
/**
* Tests, whether and how the reset button can be renamed.
*/
public function testRenameResetButton() {
// Rename the label of the reset button. // Rename the label of the reset button.
$view = views_get_view('test_reset_button'); $view = Views::getView('test_exposed_form_buttons');
$view->setDisplay(); $view->setDisplay();
$exposed_form = $view->display_handler->getOption('exposed_form'); $exposed_form = $view->display_handler->getOption('exposed_form');
...@@ -88,7 +123,7 @@ public function testRenameResetButton() { ...@@ -88,7 +123,7 @@ public function testRenameResetButton() {
views_invalidate_cache(); views_invalidate_cache();
// Look whether the reset button label changed. // Look whether the reset button label changed.
$this->drupalGet('test_reset_button', array('query' => array('type' => 'article'))); $this->drupalGet('test_exposed_form_buttons', array('query' => array('type' => 'article')));
$this->assertResponse(200); $this->assertResponse(200);
$this->helperButtonHasLabel('edit-reset', $expected_label); $this->helperButtonHasLabel('edit-reset', $expected_label);
...@@ -98,7 +133,7 @@ public function testRenameResetButton() { ...@@ -98,7 +133,7 @@ public function testRenameResetButton() {
* Tests the exposed form markup. * Tests the exposed form markup.
*/ */
public function testExposedFormRender() { public function testExposedFormRender() {
$view = views_get_view('test_reset_button'); $view = views_get_view('test_exposed_form_buttons');
$this->executeView($view); $this->executeView($view);
$exposed_form = $view->display_handler->getPlugin('exposed_form'); $exposed_form = $view->display_handler->getPlugin('exposed_form');
$output = $exposed_form->renderExposedForm(); $output = $exposed_form->renderExposedForm();
......
...@@ -45,11 +45,11 @@ display: ...@@ -45,11 +45,11 @@ display:
position: '0' position: '0'
page_1: page_1:
display_options: display_options:
path: test_reset_button path: test_exposed_form_buttons
display_plugin: page display_plugin: page
display_title: Page display_title: Page
id: page_1 id: page_1
position: '0' position: '0'
label: '' label: ''
id: test_reset_button id: test_exposed_form_buttons
tag: '' tag: ''
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment