Commit e5d5ed2d authored by Martin Keereman's avatar Martin Keereman
Browse files

Issue #3128580 by Suresh Prabhu Parkala: Fix PHPCS errors

parent 8d40cf9f
/**
* @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, // shift
17, // ctrl
18, // alt
20, // caps lock
33, // page up
34, // page down
35, // end
36, // home
37, // left arrow
38, // up arrow
39, // right arrow
40, // down arrow
9, // tab
13, // enter
27 // esc
16, // Shift.
17, // Ctrl.
18, // Alt.
20, // Caps lock.
33, // Page up.
34, // Page down.
35, // End.
36, // Home.
37, // Left arrow.
38, // Up arrow.
39, // Right arrow.
40, // Down arrow.
9, // Tab.
13, // Enter.
27 // Esc.
];
// Triggering element.
......
/**
* @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);
/**
* @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);
/**
* @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);
/**
* @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);
......@@ -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' => ' ',.
];
}
......
......@@ -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.
......
......@@ -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;
}
......
......@@ -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);
}
}
}
......
......@@ -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();
}*/
/**
......
......@@ -72,7 +72,7 @@ class SortWidgetKernelTest extends BetterExposedFiltersKernelTestBase {
'sort' => [
'advanced' => [
'combine' => TRUE,
'combine_rewrite' => "Created Desc|down\r\nCreated Asc|up"
'combine_rewrite' => "Created Desc|down\r\nCreated Asc|up",
],
],
]);
......
Supports Markdown
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