Commit 80233c4b authored by Mike Keran's avatar Mike Keran
Browse files

Issue #2846909 by mikeker, Gravypower: Placeholder support

parent 87218a29
......@@ -61,6 +61,9 @@ better_exposed_filters.*:
label: 'More options'
type: mapping
mapping:
placeholder_text:
type: text
label: 'Placeholder text for text fields'
bef_select_all_none:
type: boolean
label: 'Add select all/none links'
......
......@@ -509,6 +509,16 @@ Title Desc|Z -> A</pre> Leave the replacement text blank to remove an option alt
'#description' => $this->t('Places this element in the secondary options portion of the exposed form.'),
);
if ($filter instanceof StringFilter) {
// Allow users to specify placeholder text.
$bef_options[$label]['more_options']['placeholder_text'] = [
'#type' => 'textfield',
'#title' => $this->t('Placeholder text'),
'#description' => $this->t('Text to be shown in the text field until it is edited. Leave blank for no placeholder to be set.'),
'#default_value' => $existing[$label]['more_options']['placeholder_text'],
];
}
// Allow rewriting of filter options for any filter. String and numeric
// filters allow unlimited filter options via textfields, so we can't
// offer rewriting for those.
......@@ -855,6 +865,12 @@ Title Desc|Z -> A</pre> Leave the replacement text blank to remove an option alt
// configurable.
$field_id = $filters[$label]->options['expose']['identifier'];
// Check for placeholder text.
if (!empty($settings[$label]['more_options']['placeholder_text'])) {
// @todo: Add token replacement for placeholder text.
$form[$label]['#placeholder'] = $settings[$label]['more_options']['placeholder_text'];
}
// Handle filter value rewrites.
if (!empty($options['more_options']['rewrite']['filter_rewrite_values'])) {
$form[$field_id]['#options'] = $this->rewriteOptions($form[$field_id]['#options'] , $options['more_options']['rewrite']['filter_rewrite_values']);
......@@ -1490,6 +1506,7 @@ Title Desc|Z -> A</pre> Leave the replacement text blank to remove an option alt
$filter_defaults = array(
'bef_format' => 'default',
'more_options' => array(
'placeholder_text' => '',
'bef_select_all_none' => FALSE,
'bef_select_all_none_nested' => FALSE,
'bef_collapsible' => FALSE,
......@@ -1524,4 +1541,5 @@ Title Desc|Z -> A</pre> Leave the replacement text blank to remove an option alt
}
return $settings;
}
}
Markdown is supported
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