class RadioButtons in Better Exposed Filters 8.4
Same name in this branch
- 8.4 src/Plugin/better_exposed_filters/filter/RadioButtons.php \Drupal\better_exposed_filters\Plugin\better_exposed_filters\filter\RadioButtons
- 8.4 src/Plugin/better_exposed_filters/sort/RadioButtons.php \Drupal\better_exposed_filters\Plugin\better_exposed_filters\sort\RadioButtons
- 8.4 src/Plugin/better_exposed_filters/pager/RadioButtons.php \Drupal\better_exposed_filters\Plugin\better_exposed_filters\pager\RadioButtons
Same name and namespace in other branches
- 8.5 src/Plugin/better_exposed_filters/filter/RadioButtons.php \Drupal\better_exposed_filters\Plugin\better_exposed_filters\filter\RadioButtons
Default widget implementation.
Plugin annotation
@BetterExposedFiltersFilterWidget(
id = "bef",
label = @Translation("Checkboxes/Radio Buttons"),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\better_exposed_filters\Plugin\BetterExposedFiltersWidgetBase implements BetterExposedFiltersWidgetInterface uses StringTranslationTrait
- class \Drupal\better_exposed_filters\Plugin\better_exposed_filters\filter\FilterWidgetBase implements BetterExposedFiltersWidgetInterface uses StringTranslationTrait
- class \Drupal\better_exposed_filters\Plugin\better_exposed_filters\filter\RadioButtons
- class \Drupal\better_exposed_filters\Plugin\better_exposed_filters\filter\FilterWidgetBase implements BetterExposedFiltersWidgetInterface uses StringTranslationTrait
- class \Drupal\better_exposed_filters\Plugin\BetterExposedFiltersWidgetBase implements BetterExposedFiltersWidgetInterface uses StringTranslationTrait
Expanded class hierarchy of RadioButtons
File
- src/
Plugin/ better_exposed_filters/ filter/ RadioButtons.php, line 16
Namespace
Drupal\better_exposed_filters\Plugin\better_exposed_filters\filterView source
class RadioButtons extends FilterWidgetBase {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return parent::defaultConfiguration() + [
'select_all_none' => FALSE,
'select_all_none_nested' => FALSE,
'display_inline' => FALSE,
];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
/** @var \Drupal\views\Plugin\views\filter\FilterPluginBase $filter */
$filter = $this->handler;
$form = parent::buildConfigurationForm($form, $form_state);
$form['select_all_none'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Add select all/none links'),
'#default_value' => !empty($this->configuration['select_all_none']),
'#disabled' => !$filter->options['expose']['multiple'],
'#description' => $this
->t('Add a "Select All/None" link when rendering the exposed filter using checkboxes. If this option is disabled, edit the filter and check the "Allow multiple selections".'),
];
$form['select_all_none_nested'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Add nested all/none selection'),
'#default_value' => !empty($this->configuration['select_all_none_nested']),
'#disabled' => !$filter->options['expose']['multiple'] || isset($filter->options['hierarchy']) && !$filter->options['hierarchy'],
'#description' => $this
->t('When a parent checkbox is checked, check all its children. If this option is disabled, edit the filter and check "Allow multiple selections" and edit the filter settings and check "Show hierarchy in dropdown".'),
];
$form['display_inline'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Display inline'),
'#default_value' => !empty($this->configuration['display_inline']),
'#description' => $this
->t('Display checkbox/radio options inline.'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function exposedFormAlter(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\views\Plugin\views\filter\FilterPluginBase $filter */
$filter = $this->handler;
// Form element is designated by the element ID which is user-
// configurable.
$field_id = $filter->options['is_grouped'] ? $filter->options['group_info']['identifier'] : $filter->options['expose']['identifier'];
parent::exposedFormAlter($form, $form_state);
if (!empty($form[$field_id])) {
// Clean up filters that pass objects as options instead of strings.
if (!empty($form[$field_id]['#options'])) {
$form[$field_id]['#options'] = BetterExposedFiltersHelper::flattenOptions($form[$field_id]['#options']);
}
// Support rendering hierarchical checkboxes/radio buttons (e.g. taxonomy
// terms).
if (!empty($filter->options['hierarchy'])) {
$form[$field_id]['#bef_nested'] = TRUE;
}
// Display inline.
$form[$field_id]['#bef_display_inline'] = $this->configuration['display_inline'];
// Render as checkboxes if filter allows multiple selections.
if (!empty($form[$field_id]['#multiple'])) {
$form[$field_id]['#theme'] = 'bef_checkboxes';
$form[$field_id]['#type'] = 'checkboxes';
// Show all/none option.
$form[$field_id]['#bef_select_all_none'] = $this->configuration['select_all_none'];
$form[$field_id]['#bef_select_all_none_nested'] = $this->configuration['select_all_none_nested'];
// Attach the JS (@see /js/bef_select_all_none.js)
$form['#attached']['library'][] = 'better_exposed_filters/select_all_none';
}
else {
$form[$field_id]['#theme'] = 'bef_radios';
$form[$field_id]['#type'] = 'radios';
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BetterExposedFiltersWidgetBase:: |
protected | property | The views plugin this configuration will affect when exposed. | |
BetterExposedFiltersWidgetBase:: |
protected | property | The views executable object. | |
BetterExposedFiltersWidgetBase:: |
protected | function | Sets metadata on the form elements for easier processing. | |
BetterExposedFiltersWidgetBase:: |
protected | function | Moves an exposed form element into a field group. | |
BetterExposedFiltersWidgetBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
BetterExposedFiltersWidgetBase:: |
protected | function | Returns exposed form action URL object. | |
BetterExposedFiltersWidgetBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
BetterExposedFiltersWidgetBase:: |
public | function |
Sets the view object. Overrides BetterExposedFiltersWidgetInterface:: |
|
BetterExposedFiltersWidgetBase:: |
public | function |
Sets the exposed view handler plugin. Overrides BetterExposedFiltersWidgetInterface:: |
|
BetterExposedFiltersWidgetBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
BetterExposedFiltersWidgetBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
1 |
BetterExposedFiltersWidgetBase:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
|
FilterWidgetBase:: |
protected | function | Helper function to get the unique identifier for the exposed filter. | |
FilterWidgetBase:: |
protected | function | Helper function to get the widget type of the exposed filter. | |
FilterWidgetBase:: |
public static | function |
Verify this plugin can be used on the form element. Overrides BetterExposedFiltersWidgetInterface:: |
5 |
FilterWidgetBase:: |
public | function | Sorts the options for a given form element alphabetically. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
RadioButtons:: |
public | function |
Form constructor. Overrides FilterWidgetBase:: |
|
RadioButtons:: |
public | function |
Gets default configuration for this plugin. Overrides FilterWidgetBase:: |
|
RadioButtons:: |
public | function |
Manipulate views exposed from element. Overrides FilterWidgetBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |