Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
afa7d30c
Commit
afa7d30c
authored
Dec 06, 2013
by
catch
Browse files
Issue
#2149751
by damiankloip: Views exposed forms are broken.
parent
e8c263c4
Changes
3
Hide whitespace changes
Inline
Side-by-side
core/modules/views/lib/Drupal/views/Plugin/views/exposed_form/ExposedFormPluginBase.php
View file @
afa7d30c
...
...
@@ -181,8 +181,19 @@ public function preExecute() { }
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
)
{
$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
$exposed_sorts
=
array
();
foreach
(
$this
->
view
->
sort
as
$id
=>
$handler
)
{
...
...
@@ -226,7 +237,7 @@ public function exposedFormAlter(&$form, &$form_state) {
}
if
(
!
empty
(
$this
->
options
[
'reset_button'
]))
{
$form
[
'reset'
]
=
array
(
$form
[
'
actions'
][
'
reset'
]
=
array
(
'#value'
=>
$this
->
options
[
'reset_button_label'
],
'#type'
=>
'submit'
,
'#weight'
=>
10
,
...
...
@@ -242,7 +253,7 @@ public function exposedFormAlter(&$form, &$form_state) {
// 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
;
$form
[
'
actions'
][
'
reset'
][
'#access'
]
=
FALSE
;
}
}
...
...
core/modules/views/lib/Drupal/views/Tests/Plugin/ExposedFormTest.php
View file @
afa7d30c
...
...
@@ -21,7 +21,7 @@ class ExposedFormTest extends ViewTestBase {
*
* @var array
*/
public
static
$testViews
=
array
(
'test_
reset
_button'
,
'test_exposed_block'
);
public
static
$testViews
=
array
(
'test_
exposed_form
_button
s
'
,
'test_exposed_block'
);
/**
* Modules to enable.
...
...
@@ -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.
*/
public
function
testResetButton
()
{
// Test the button is hidden when there is no exposed input.
$this
->
drupalGet
(
'test_
reset
_button'
);
$this
->
drupalGet
(
'test_
exposed_form
_button
s
'
);
$this
->
assertNoField
(
'edit-reset'
);
$this
->
drupalGet
(
'test_
reset
_button'
,
array
(
'query'
=>
array
(
'type'
=>
'article'
)));
$this
->
drupalGet
(
'test_
exposed_form
_button
s
'
,
array
(
'query'
=>
array
(
'type'
=>
'article'
)));
// Test that the type has been set.
$this
->
assertFieldById
(
'edit-type'
,
'article'
,
'Article type filter set.'
);
// Test the reset works.
$this
->
drupalGet
(
'test_
reset
_button'
,
array
(
'query'
=>
array
(
'op'
=>
'Reset'
)));
$this
->
drupalGet
(
'test_
exposed_form
_button
s
'
,
array
(
'query'
=>
array
(
'op'
=>
'Reset'
)));
$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
()
{
// Rename the label of the reset button.
$view
=
v
iews
_
get
_v
iew
(
'test_
reset
_button'
);
$view
=
V
iews
::
get
V
iew
(
'test_
exposed_form
_button
s
'
);
$view
->
setDisplay
();
$exposed_form
=
$view
->
display_handler
->
getOption
(
'exposed_form'
);
...
...
@@ -88,7 +123,7 @@ public function testRenameResetButton() {
views_invalidate_cache
();
// Look whether the reset button label changed.
$this
->
drupalGet
(
'test_
reset
_button'
,
array
(
'query'
=>
array
(
'type'
=>
'article'
)));
$this
->
drupalGet
(
'test_
exposed_form
_button
s
'
,
array
(
'query'
=>
array
(
'type'
=>
'article'
)));
$this
->
assertResponse
(
200
);
$this
->
helperButtonHasLabel
(
'edit-reset'
,
$expected_label
);
...
...
@@ -98,7 +133,7 @@ public function testRenameResetButton() {
* Tests the exposed form markup.
*/
public
function
testExposedFormRender
()
{
$view
=
views_get_view
(
'test_
reset
_button'
);
$view
=
views_get_view
(
'test_
exposed_form
_button
s
'
);
$this
->
executeView
(
$view
);
$exposed_form
=
$view
->
display_handler
->
getPlugin
(
'exposed_form'
);
$output
=
$exposed_form
->
renderExposedForm
();
...
...
core/modules/views/tests/modules/views_test_config/test_views/views.view.test_
reset
_button.yml
→
core/modules/views/tests/modules/views_test_config/test_views/views.view.test_
exposed_form
_button
s
.yml
View file @
afa7d30c
...
...
@@ -45,11 +45,11 @@ display:
position
:
'
0'
page_1
:
display_options
:
path
:
test_
reset
_button
path
:
test_
exposed_form
_button
s
display_plugin
:
page
display_title
:
Page
id
:
page_1
position
:
'
0'
label
:
'
'
id
:
test_
reset
_button
id
:
test_
exposed_form
_button
s
tag
:
'
'
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment