Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
drupal.org
better_exposed_filters
Commits
84311312
Commit
84311312
authored
Apr 13, 2018
by
focus13
Committed by
Rick Hawkins
Apr 13, 2018
Browse files
Issue #2947281 by focus13: Single on/off checkbox is always checked
parent
7f85745e
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/Plugin/views/exposed_form/BetterExposedFilters.php
View file @
84311312
...
...
@@ -1110,8 +1110,36 @@ Title Desc|Z -> A</pre> Leave the replacement text blank to remove an option alt
// Use filter label as checkbox label.
$form
[
$field_id
][
'#title'
]
=
$filters
[
$label
]
->
options
[
'expose'
][
'label'
];
$form
[
$field_id
][
'#return_value'
]
=
1
;
$form
[
$field_id
][
'#type'
]
=
'checkbox'
;
// Views populates missing values in $form_state['input'] with the
// defaults and a checkbox does not appear in $_GET (or $_POST) so it
// will appear to be missing when a user submits a form. Because of
// this, instead of unchecking the checkbox value will revert to the
// default. More, the default value for select values is reused which
// results in the checkbox always checked. So we need to add a form
// element to see whether the form is submitted or not and then we
// need to look at $_GET directly to see whether the checkbox is
// there. For security reasons, we must not copy the $_GET value.
// First, let's figure out a short name for the signal element and
// then add it.
if
(
empty
(
$signal
))
{
for
(
$signal
=
'a'
;
isset
(
$form
[
$signal
]);
$signal
++
);
// This is all the signal element needs.
$form
[
$signal
][
'#type'
]
=
'hidden'
;
}
$input
=
$form_state
->
getUserInput
();
$value
=
\
Drupal
::
request
()
->
query
->
get
(
$field_id
);
$checked
=
isset
(
$input
[
$signal
])
?
isset
(
$value
)
:
$form
[
$field_id
][
'#default_value'
];
// For security, we check if value is valid and exist.
if
(
$checked
)
{
if
(
!
in_array
(
$value
,
array_keys
(
$form
[
$field_id
][
'#options'
])))
{
$checked
=
FALSE
;
}
}
// Now we know whether the checkbox is checked or not, set #value
// accordingly.
$form
[
$field_id
][
'#value'
]
=
$checked
?
$value
:
0
;
break
;
case
'bef'
:
...
...
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