Commit 1d8aaefc authored by rocket.man's avatar rocket.man Committed by Mike Keran
Browse files

Issue #2655788 by rocket.man: Allow token replacements in description field

parent b0555511
......@@ -56,6 +56,26 @@ function better_exposed_filters_theme($existing, $type, $theme, $path) {
);
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function better_exposed_filters_form_views_ui_config_item_form_alter(&$form, FormStateInterface $form_state) {
// Checks if Token module is enabled.
if (!\Drupal::moduleHandler()->moduleExists('token')) {
return;
}
// Adds global token replacements, if available.
$form['options']['expose']['global_replacement_tokens'] = array(
'#title' => t('Global replacement patterns (for description field only)'),
'#type' => 'details',
'#weight' => 151,
);
$form['options']['expose']['global_replacement_tokens']['list'] = array(
'#theme' => 'token_tree_link',
'#token_types' => array(),
);
}
/******************************************************************************
* Preprocess functions for BEF themed elements.
******************************************************************************/
......@@ -194,6 +214,29 @@ function template_preprocess_bef_links(&$variables) {
_bef_preprocess_nested_elements($variables);
}
/**
* Prepares variables for views exposed form templates.
*
* Default template: views-exposed-form.html.twig.
*
* @param array $variables
* An associative array containing:
* - form: A render element representing the form.
*/
function better_exposed_filters_preprocess_views_exposed_form(&$variables) {
// Checks if Token module is enabled.
if (!\Drupal::moduleHandler()->moduleExists('token')) {
return;
}
// Replaces tokens in description field of the exposed filter.
foreach ($variables['form']['#info'] as $name => &$info) {
if (isset($info['description']) && isset($variables['form'][explode('filter-', $name)[1]]['#description'])) {
$info['description'] = \Drupal::service('token')->replace($info['description']);
$variables['form'][explode('filter-', $name)[1]]['#description'] = $info['description'];
}
}
}
/******************************************************************************
* Utility functions for BEF themed elements.
******************************************************************************/
......
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