Issue #1960094 by damiankloip, dawehner: Hide reset button when no exposed input has been added.

8.0.x
Alex Pott 2013-05-13 12:50:07 +01:00
parent a21ee2d711
commit 1f39cc4b01
2 changed files with 29 additions and 13 deletions

View File

@ -183,13 +183,6 @@ abstract class ExposedFormPluginBase extends PluginBase {
public function postExecute() { }
function exposed_form_alter(&$form, &$form_state) {
if (!empty($this->options['reset_button'])) {
$form['reset'] = array(
'#value' => $this->options['reset_button_label'],
'#type' => 'submit',
);
}
$form['submit']['#value'] = $this->options['submit_button'];
// Check if there is exposed sorts for this view
$exposed_sorts = array();
@ -231,8 +224,26 @@ abstract class ExposedFormPluginBase extends PluginBase {
);
}
$form['submit']['#weight'] = 10;
if (isset($form['reset'])) {
$form['reset']['#weight'] = 10;
}
if (!empty($this->options['reset_button'])) {
$form['reset'] = array(
'#value' => $this->options['reset_button_label'],
'#type' => 'submit',
'#weight' => 10,
);
// Get an array of exposed filters, keyed by identifier option.
foreach ($this->view->filter as $id => $handler) {
if ($handler->canExpose() && $handler->isExposed() && !empty($handler->options['expose']['identifier'])) {
$exposed_filters[$handler->options['expose']['identifier']] = $id;
}
}
$all_exposed = array_merge($exposed_sorts, $exposed_filters);
// Set the access to FALSE if there is no exposed input.
if (!array_intersect_key($all_exposed, $this->view->exposed_input)) {
$form['reset']['#access'] = FALSE;
}
}

View File

@ -51,6 +51,10 @@ class ExposedFormTest extends ViewTestBase {
* Tests whether the reset button works on an exposed form.
*/
public function testResetButton() {
// Test the button is hidden when there is no exposed input.
$this->drupalGet('test_reset_button');
$this->assertNoField('edit-reset');
$this->drupalGet('test_reset_button', array('query' => array('type' => 'article')));
// Test that the type has been set.
$this->assertFieldById('edit-type', 'article', 'Article type filter set.');
@ -60,14 +64,15 @@ class ExposedFormTest extends ViewTestBase {
$this->assertResponse(200);
// Test the type has been reset.
$this->assertFieldById('edit-type', 'All', 'Article type filter has been reset.');
// Test the button is hidden after reset.
$this->assertNoField('edit-reset');
}
/**
* Tests, whether and how the reset button can be renamed.
*/
public function testRenameResetButton() {
// Look at the page and check the label "reset".
$this->drupalGet('test_reset_button');
// Rename the label of the reset button.
$view = views_get_view('test_reset_button');
$view->setDisplay();
@ -80,8 +85,8 @@ class ExposedFormTest extends ViewTestBase {
views_invalidate_cache();
// Look whether ther reset button label changed.
$this->drupalGet('test_reset_button');
// Look whether the reset button label changed.
$this->drupalGet('test_reset_button', array('query' => array('type' => 'article')));
$this->assertResponse(200);
$this->helperButtonHasLabel('edit-reset', $expected_label);