Commit 1f39cc4b authored by alexpott's avatar alexpott
Browse files

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

parent a21ee2d7
......@@ -183,13 +183,6 @@ function pre_execute() { }
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 @@ function exposed_form_alter(&$form, &$form_state) {
);
}
$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;
}
}
......
......@@ -51,6 +51,10 @@ protected function setUp() {
* 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 @@ public function testResetButton() {
$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 @@ public function testRenameResetButton() {
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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment