You are here

function better_exposed_filters_form_views_ui_config_item_form_alter in Better Exposed Filters 8.4

Same name and namespace in other branches
  1. 8.5 better_exposed_filters.module \better_exposed_filters_form_views_ui_config_item_form_alter()
  2. 8.3 better_exposed_filters.module \better_exposed_filters_form_views_ui_config_item_form_alter()

Implements hook_form_FORM_ID_alter().

File

./better_exposed_filters.module, line 44
General functions and hook implementations.

Code

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')) {
    $text = t('Enable the Token module to allow token replacement in this field.');
    if (empty($form['options']['expose']['description']['#description'])) {
      $form['options']['expose']['description']['#description'] = $text;
    }
    else {
      $form['options']['expose']['description']['#description'] .= " {$text}";
    }
    return;
  }

  // Adds global token replacements, if available.
  $text = t('Tokens are allowed in this field. Replacement options can be found in the "Global replacement patterns" section, below.');
  if (empty($form['options']['expose']['description']['#description'])) {
    $form['options']['expose']['description']['#description'] = $text;
  }
  else {
    $form['options']['expose']['description']['#description'] .= " {$text}";
  }
  $form['options']['expose']['global_replacement_tokens'] = [
    '#title' => t('Global replacement patterns (for description field only)'),
    '#type' => 'details',
    '#weight' => 151,
  ];
  $form['options']['expose']['global_replacement_tokens']['list'] = [
    '#theme' => 'token_tree_link',
    '#token_types' => [],
  ];
}