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
e5d5ed2d
Commit
e5d5ed2d
authored
Apr 17, 2020
by
Martin Keereman
Browse files
Issue #3128580 by Suresh Prabhu Parkala: Fix PHPCS errors
parent
8d40cf9f
Changes
11
Hide whitespace changes
Inline
Side-by-side
js/auto_submit.js
View file @
e5d5ed2d
/**
* @file auto_submit.js
* @file
* auto_submit.js
*
* Provides a "form auto-submit" feature for the Better Exposed Filters module.
*/
...
...
@@ -7,7 +8,7 @@
(
function
(
$
,
Drupal
)
{
/**
* To make a form auto submit, all you have to do is 3 things:
* To make a form auto submit, all you have to do is 3 things:
.
*
* Use the "better_exposed_filters/auto_submit" js library.
*
...
...
@@ -40,7 +41,7 @@
* supported. We probably could use additional support for HTML5 input types.
*/
Drupal
.
behaviors
.
betterExposedFiltersAutoSubmit
=
{
attach
:
function
(
context
)
{
attach
:
function
(
context
)
{
// When exposed as a block, the form #attributes are moved from the form
// to the block element, thus the second selector.
// @see \Drupal\block\BlockViewBuilder::preRender
...
...
@@ -48,7 +49,7 @@
// The change event bubbles so we only need to bind it to the outer form
// in case of a full form, or a single element when specified explicitly.
$
(
selectors
,
context
).
addBack
(
selectors
).
each
(
function
(
i
,
e
)
{
$
(
selectors
,
context
).
addBack
(
selectors
).
each
(
function
(
i
,
e
)
{
// Store the current form.
var
$form
=
$
(
e
);
...
...
@@ -74,24 +75,24 @@
*
* @param {object} e - The triggering event.
*/
function
triggerSubmit
(
e
)
{
function
triggerSubmit
(
e
)
{
// e.keyCode: key.
var
ignoredKeyCodes
=
[
16
,
//
s
hift
17
,
//
c
trl
18
,
//
a
lt
20
,
//
c
aps lock
33
,
//
p
age up
34
,
//
p
age down
35
,
//
e
nd
36
,
//
h
ome
37
,
//
l
eft arrow
38
,
//
u
p arrow
39
,
//
r
ight arrow
40
,
//
d
own arrow
9
,
//
t
ab
13
,
//
e
nter
27
//
e
sc
16
,
//
S
hift
.
17
,
//
C
trl
.
18
,
//
A
lt
.
20
,
//
C
aps lock
.
33
,
//
P
age up
.
34
,
//
P
age down
.
35
,
//
E
nd
.
36
,
//
H
ome
.
37
,
//
L
eft arrow
.
38
,
//
U
p arrow
.
39
,
//
R
ight arrow
.
40
,
//
D
own arrow
.
9
,
//
T
ab
.
13
,
//
E
nter
.
27
//
E
sc
.
];
// Triggering element.
...
...
js/bef_datepickers.js
View file @
e5d5ed2d
/**
* @file bef_datepickers.js
* @file
* bef_datepickers.js
*
* Provides jQueryUI Datepicker integration with Better Exposed Filters.
*/
...
...
@@ -10,13 +11,13 @@
*/
Drupal
.
behaviors
.
betterExposedFiltersDatePickers
=
{
attach
:
function
(
context
,
settings
)
{
attach
:
function
(
context
,
settings
)
{
// Check for and initialize datepickers
// Check for and initialize datepickers
.
var
befSettings
=
drupalSettings
.
better_exposed_filters
;
if
(
befSettings
&&
befSettings
.
datepicker
&&
befSettings
.
datepicker_options
&&
$
.
fn
.
datepicker
)
{
var
opt
=
[];
$
.
each
(
befSettings
.
datepicker_options
,
function
(
key
,
val
)
{
$
.
each
(
befSettings
.
datepicker_options
,
function
(
key
,
val
)
{
if
(
key
&&
val
)
{
opt
[
key
]
=
JSON
.
parse
(
val
);
}
...
...
@@ -26,4 +27,4 @@
}
};
})
(
jQuery
,
Drupal
,
drupalSettings
);
})(
jQuery
,
Drupal
,
drupalSettings
);
js/bef_select_all_none.js
View file @
e5d5ed2d
/**
* @file bef_select_all_none.js
* @file
* bef_select_all_none.js
*
* Adds select all/none toggle functionality to an exposed filter.
*/
(
function
(
$
)
{
Drupal
.
behaviors
.
betterExposedFiltersSelectAllNone
=
{
attach
:
function
(
context
)
{
...
...
@@ -14,7 +16,7 @@
var
selAll
=
Drupal
.
t
(
'
Select All
'
);
var
selNone
=
Drupal
.
t
(
'
Select None
'
);
// Set up a prototype link and event handlers
// Set up a prototype link and event handlers
.
var
link
=
$
(
'
<a class="bef-toggle" href="#">
'
+
selAll
+
'
</a>
'
)
link
.
click
(
function
(
event
)
{
// Don't actually follow the link...
...
...
@@ -22,38 +24,36 @@
event
.
stopPropagation
();
if
(
selAll
==
$
(
this
).
text
())
{
// Select all the checkboxes
// Select all the checkboxes
.
$
(
this
)
.
html
(
selNone
)
.
siblings
(
'
.bef-select-all-none, .bef-tree
'
)
.
find
(
'
input:checkbox
'
).
each
(
function
()
{
$
(
this
).
prop
(
'
checked
'
,
true
);
// @TODO:
//_bef_highlight(this, context);
//
_bef_highlight(this, context);
})
.
end
()
// attr() doesn't trigger a change event, so we do it ourselves. But just on
// one checkbox otherwise we have many spinning cursors
.
find
(
'
input[type=checkbox]:first
'
).
change
()
;
// one checkbox otherwise we have many spinning cursors.
.
find
(
'
input[type=checkbox]:first
'
).
change
();
}
else
{
// Unselect all the checkboxes
// Unselect all the checkboxes
.
$
(
this
)
.
html
(
selAll
)
.
siblings
(
'
.bef-select-all-none, .bef-tree
'
)
.
find
(
'
input:checkbox
'
).
each
(
function
()
{
$
(
this
).
prop
(
'
checked
'
,
false
);
// @TODO:
//_bef_highlight(this, context);
//
_bef_highlight(this, context);
})
.
end
()
// attr() doesn't trigger a change event, so we do it ourselves. But just on
// one checkbox otherwise we have many spinning cursors
.
find
(
'
input[type=checkbox]:first
'
).
change
()
;
// one checkbox otherwise we have many spinning cursors.
.
find
(
'
input[type=checkbox]:first
'
).
change
();
}
});
...
...
@@ -61,32 +61,30 @@
selected
.
addClass
(
'
bef-processed
'
)
.
each
(
function
(
index
)
{
// Clone the link prototype and insert into the DOM
// Clone the link prototype and insert into the DOM
.
var
newLink
=
link
.
clone
(
true
);
newLink
.
insertBefore
(
$
(
this
));
// If all checkboxes are already checked by default then switch to Select None
// If all checkboxes are already checked by default then switch to Select None
.
if
(
$
(
'
input:checkbox:checked
'
,
this
).
length
==
$
(
'
input:checkbox
'
,
this
).
length
)
{
newLink
.
text
(
selNone
);
}
})
;
});
}
// @TODO:
// Add highlight class to checked checkboxes for better theming
//$('.bef-tree input[type="checkbox"], .bef-checkboxes input[type="checkbox"]')
//
//
Highlight newly selected checkboxes
//
$('.bef-tree input[type="checkbox"], .bef-checkboxes input[type="checkbox"]')
// Highlight newly selected checkboxes
// .change(function () {
// _bef_highlight(this, context);
// })
// .filter(':checked').closest('.form-item', context).addClass('highlight')
//;
// ;
// @TODO: Put this somewhere else...
// Check for and initialize datepickers
//if (Drupal.settings.better_exposed_filters.datepicker) {
//
if (Drupal.settings.better_exposed_filters.datepicker) {
// // Note: JavaScript does not treat "" as null
// if (Drupal.settings.better_exposed_filters.datepicker_options.dateformat) {
// $('.bef-datepicker').datepicker({
...
...
@@ -96,23 +94,22 @@
// else {
// $('.bef-datepicker').datepicker();
// }
//}
// }
}
// attach: function() {
};
// Drupal.behaviors.better_exposed_filters = {
};
// Drupal.behaviors.better_exposed_filters = {
.
Drupal
.
behaviors
.
betterExposedFiltersAllNoneNested
=
{
attach
:
function
(
context
,
settings
)
{
$
(
'
.bef-select-all-none-nested li
'
).
has
(
'
ul
'
).
once
(
'
bef-all-none-nested
'
).
each
(
function
()
{
var
$this
=
$
(
this
);
// Check/uncheck child terms along with their parent.
$this
.
find
(
'
input:checkbox:first
'
).
change
(
function
()
{
$this
.
find
(
'
input:checkbox:first
'
).
change
(
function
()
{
$
(
this
).
closest
(
'
li
'
).
find
(
'
ul li input:checkbox
'
).
prop
(
'
checked
'
,
this
.
checked
);
});
// When a child term is checked or unchecked, set the parent term's
// status as needed.
$this
.
find
(
'
ul input:checkbox
'
).
change
(
function
()
{
$this
.
find
(
'
ul input:checkbox
'
).
change
(
function
()
{
// Determine the number of unchecked sibling checkboxes.
var
$this
=
$
(
this
);
var
uncheckedSiblings
=
$this
.
closest
(
'
li
'
).
siblings
(
'
li
'
).
find
(
'
> div > input:checkbox:not(:checked)
'
).
length
;
...
...
@@ -134,4 +131,4 @@
}
}
})
(
jQuery
);
})(
jQuery
);
js/bef_sliders.js
View file @
e5d5ed2d
/**
* @file bef_sliders.js
* @file
* bef_sliders.js
*
* Adds jQuery UI Slider functionality to an exposed filter.
*/
(
function
(
$
,
Drupal
,
drupalSettings
)
{
Drupal
.
behaviors
.
better_exposed_filters_slider
=
{
attach
:
function
(
context
,
settings
)
{
attach
:
function
(
context
,
settings
)
{
if
(
drupalSettings
.
better_exposed_filters
.
slider
)
{
$
.
each
(
drupalSettings
.
better_exposed_filters
.
slider_options
,
function
(
i
,
sliderOptions
)
{
var
data_selector
=
'
edit-
'
+
sliderOptions
.
dataSelector
;
...
...
@@ -79,7 +81,7 @@
animate
:
sliderOptions
.
animate
?
sliderOptions
.
animate
:
false
,
orientation
:
sliderOptions
.
orientation
,
values
:
[
defaultMin
,
defaultMax
],
// Update the textfields as the sliders are moved
// Update the textfields as the sliders are moved
.
slide
:
function
(
event
,
ui
)
{
$min
.
val
(
ui
.
values
[
0
]);
$max
.
val
(
ui
.
values
[
1
]);
...
...
@@ -95,7 +97,7 @@
$max
.
val
(
ui
.
values
[
1
]);
},
// Attach stop listeners.
stop
:
function
(
event
,
ui
)
{
stop
:
function
(
event
,
ui
)
{
// Click the auto submit button.
$
(
this
).
parents
(
'
form
'
).
find
(
'
.ctools-auto-submit-click
'
).
click
();
}
...
...
@@ -104,10 +106,10 @@
$min
.
after
(
slider
);
// Update the slider when the fields are updated.
$min
.
blur
(
function
()
{
$min
.
blur
(
function
()
{
befUpdateSlider
(
$
(
this
),
0
,
sliderOptions
);
});
$max
.
blur
(
function
()
{
$max
.
blur
(
function
()
{
befUpdateSlider
(
$
(
this
),
1
,
sliderOptions
);
});
}
...
...
@@ -175,4 +177,4 @@
}
}
})
(
jQuery
,
Drupal
,
drupalSettings
);
})(
jQuery
,
Drupal
,
drupalSettings
);
js/better_exposed_filters.js
View file @
e5d5ed2d
/**
* @file better_exposed_filters.js
* @file
* better_exposed_filters.js
*
* Provides some client-side functionality for the Better Exposed Filters module
* Provides some client-side functionality for the Better Exposed Filters module
.
*/
(
function
(
$
,
Drupal
,
drupalSettings
)
{
Drupal
.
behaviors
.
betterExposedFilters
=
{
attach
:
function
(
context
,
settings
)
{
// Add highlight class to checked checkboxes for better theming
attach
:
function
(
context
,
settings
)
{
// Add highlight class to checked checkboxes for better theming
.
$
(
'
.bef-tree input[type=checkbox], .bef-checkboxes input[type=checkbox]
'
)
// Highlight newly selected checkboxes
.
change
(
function
()
{
// Highlight newly selected checkboxes
.
.
change
(
function
()
{
_bef_highlight
(
this
,
context
);
})
.
filter
(
'
:checked
'
).
closest
(
'
.form-item
'
,
context
).
addClass
(
'
highlight
'
)
;
.
filter
(
'
:checked
'
).
closest
(
'
.form-item
'
,
context
).
addClass
(
'
highlight
'
);
}
};
...
...
@@ -22,7 +23,7 @@
*/
/**
* Adds/Removes the highlight class from the form-item div as appropriate
* Adds/Removes the highlight class from the form-item div as appropriate
.
*/
function
_bef_highlight
(
elem
,
context
)
{
$elem
=
$
(
elem
,
context
);
...
...
@@ -31,4 +32,4 @@
:
$elem
.
closest
(
'
.form-item
'
,
context
).
removeClass
(
'
highlight
'
);
}
})
(
jQuery
,
Drupal
,
drupalSettings
);
})(
jQuery
,
Drupal
,
drupalSettings
);
src/Plugin/better_exposed_filters/filter/DatePickers.php
View file @
e5d5ed2d
...
...
@@ -132,7 +132,7 @@ class DatePickers extends FilterWidgetBase {
/* Week */
// ISO-8601 week number of year, weeks starting on Monday (added
// in PHP 4.1.0) Example: 42 (the 42nd week in the year).
// 'W' => ' ',
// 'W' => ' ',
.
/* Month */
// A full textual representation of a month, such as January or
// March January through December.
...
...
@@ -147,7 +147,7 @@ class DatePickers extends FilterWidgetBase {
// through 12.
'n'
=>
'm'
,
// Number of days in the given month 28 through 31.
// 't' => ' ',
// 't' => ' ',
.
/* Year */
// Whether it's a leap year 1 if it is a leap year, 0 otherwise.
// 'L' => ' ',
...
...
@@ -182,7 +182,7 @@ class DatePickers extends FilterWidgetBase {
// Seconds, with leading zeros 00 through 59.
// 's' => ' ',
// Microseconds (added in PHP 5.2.2) Example: 654321.
// 'u' => ' ',
// 'u' => ' ',
.
];
}
...
...
src/Plugin/better_exposed_filters/filter/FilterWidgetBase.php
View file @
e5d5ed2d
...
...
@@ -185,10 +185,10 @@ abstract class FilterWidgetBase extends BetterExposedFiltersWidgetBase implement
if
(
$this
->
configuration
[
'advanced'
][
'rewrite'
][
'filter_rewrite_values'
])
{
$form
[
$field_id
][
'#options'
]
=
BetterExposedFiltersHelper
::
rewriteOptions
(
$form
[
$field_id
][
'#options'
],
$this
->
configuration
[
'advanced'
][
'rewrite'
][
'filter_rewrite_values'
]);
// @todo what is $selected?
//if (isset($selected) && !isset($form[$field_id]['#options'][$selected])) {
// Avoid "Illegal choice" errors.
//$form[$field_id]['#default_value'] = NULL;
//}
//
if (isset($selected) && !isset($form[$field_id]['#options'][$selected])) {
// Avoid "Illegal choice" errors.
//
$form[$field_id]['#default_value'] = NULL;
//
}
}
// Identify all exposed filter elements.
...
...
src/Plugin/better_exposed_filters/filter/Single.php
View file @
e5d5ed2d
...
...
@@ -26,7 +26,7 @@ class Single extends FilterWidgetBase {
return
$is_applicable
;
}
if
(
is_a
(
$filter
,
'Drupal\views\Plugin\views\filter\BooleanOperator'
)
||
(
$filter
->
isAGroup
()
&&
sizeOf
(
$filter
->
options
[
'group_info'
][
'group_items'
])
==
1
))
{
if
(
is_a
(
$filter
,
'Drupal\views\Plugin\views\filter\BooleanOperator'
)
||
(
$filter
->
isAGroup
()
&&
count
(
$filter
->
options
[
'group_info'
][
'group_items'
])
==
1
))
{
$is_applicable
=
TRUE
;
}
...
...
src/Plugin/views/exposed_form/BetterExposedFilters.php
View file @
e5d5ed2d
...
...
@@ -708,7 +708,7 @@ class BetterExposedFilters extends InputRequired {
'#attributes'
=>
[
'data-bef-auto-submit-full-form'
=>
''
,
'data-bef-auto-submit'
=>
''
,
'data-bef-auto-submit-delay'
=>
$bef_options
[
'general'
][
'autosubmit_textfield_delay'
]
'data-bef-auto-submit-delay'
=>
$bef_options
[
'general'
][
'autosubmit_textfield_delay'
]
,
],
]);
$form
[
'actions'
][
'submit'
][
'#attributes'
][
'data-bef-auto-submit-click'
]
=
''
;
...
...
@@ -787,16 +787,16 @@ class BetterExposedFilters extends InputRequired {
foreach
(
$bef_options
[
'filter'
]
as
$filter_id
=>
$filter_options
)
{
// Sanity check: Ensure this filter is an exposed filter.
if
(
empty
(
$filters
[
$filter_id
])
||
!
$filters
[
$filter_id
]
->
isExposed
())
{
continue
;
continue
;
}
$plugin_id
=
$filter_options
[
'plugin_id'
];
if
(
$plugin_id
)
{
/** @var \Drupal\better_exposed_filters\Plugin\BetterExposedFiltersWidgetInterface $plugin */
$plugin
=
$this
->
filterWidgetManager
->
createInstance
(
$plugin_id
,
$filter_options
);
$plugin
->
setView
(
$this
->
view
);
$plugin
->
setViewsHandler
(
$filters
[
$filter_id
]);
$plugin
->
exposedFormAlter
(
$form
,
$form_state
);
/** @var \Drupal\better_exposed_filters\Plugin\BetterExposedFiltersWidgetInterface $plugin */
$plugin
=
$this
->
filterWidgetManager
->
createInstance
(
$plugin_id
,
$filter_options
);
$plugin
->
setView
(
$this
->
view
);
$plugin
->
setViewsHandler
(
$filters
[
$filter_id
]);
$plugin
->
exposedFormAlter
(
$form
,
$form_state
);
}
}
}
...
...
tests/src/Kernel/Plugin/filter/FilterWidgetKernelTest.php
View file @
e5d5ed2d
...
...
@@ -29,44 +29,44 @@ class FilterWidgetKernelTest extends BetterExposedFiltersKernelTestBase {
* is fixed
*/
/*public function testGroupedFilters() {
$view = Views::getView('bef_test');
$display = &$view->storage->getDisplay('default');
// Ensure our filter "field_bef_boolean_value" is grouped.
$display['display_options']['filters']['field_bef_boolean_value']['is_grouped'] = TRUE;
$display['display_options']['filters']['field_bef_boolean_value']['group_info'] = [
'plugin_id' => 'boolean',
'label' => 'bef_boolean (field_bef_boolean)',
'description' => '',
'identifier' => 'field_bef_boolean_value2',
'optional' => TRUE,
'widget' => 'select',
'multiple' => FALSE,
'remember' => FALSE,
'default_group' => 'All',
'default_group_multiple' => [],
'group_items' => [
1 => [
'title' => 'YES',
'operator' => '=',
'value' => '1',
],
2 => [
'title' => 'NO',
'operator' => '=',
'value' => '0',
],
],
];
// Render the exposed form.
$output = $this->getExposedFormRenderArray($view);
// Check our "FIELD_BEF_BOOLEAN" filter is rendered with id
// "field_bef_boolean_value2".
$this->assertTrue(isset($output['field_bef_boolean_value2']), 'Exposed filter "FIELD_BEF_BOOLEAN" is exposed with id "field_bef_boolean_value2".');
$view->destroy();
$view = Views::getView('bef_test');
$display = &$view->storage->getDisplay('default');
// Ensure our filter "field_bef_boolean_value" is grouped.
$display['display_options']['filters']['field_bef_boolean_value']['is_grouped'] = TRUE;
$display['display_options']['filters']['field_bef_boolean_value']['group_info'] = [
'plugin_id' => 'boolean',
'label' => 'bef_boolean (field_bef_boolean)',
'description' => '',
'identifier' => 'field_bef_boolean_value2',
'optional' => TRUE,
'widget' => 'select',
'multiple' => FALSE,
'remember' => FALSE,
'default_group' => 'All',
'default_group_multiple' => [],
'group_items' => [
1 => [
'title' => 'YES',
'operator' => '=',
'value' => '1',
],
2 => [
'title' => 'NO',
'operator' => '=',
'value' => '0',
],
],
];
// Render the exposed form.
$output = $this->getExposedFormRenderArray($view);
// Check our "FIELD_BEF_BOOLEAN" filter is rendered with id
// "field_bef_boolean_value2".
$this->assertTrue(isset($output['field_bef_boolean_value2']), 'Exposed filter "FIELD_BEF_BOOLEAN" is exposed with id "field_bef_boolean_value2".');
$view->destroy();
}*/
/**
...
...
tests/src/Kernel/Plugin/sort/SortWidgetKernelTest.php
View file @
e5d5ed2d
...
...
@@ -72,7 +72,7 @@ class SortWidgetKernelTest extends BetterExposedFiltersKernelTestBase {
'sort'
=>
[
'advanced'
=>
[
'combine'
=>
TRUE
,
'combine_rewrite'
=>
"Created Desc|down
\r\n
Created Asc|up"
'combine_rewrite'
=>
"Created Desc|down
\r\n
Created Asc|up"
,
],
],
]);
...
...
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