You are here

function shs_chosen_shs_js_settings_alter in Simple hierarchical select 8

Same name and namespace in other branches
  1. 2.0.x modules/shs_chosen/shs_chosen.module \shs_chosen_shs_js_settings_alter()

Alter Javascript settings of shs widgets in entity forms and views.

Parameters

array $settings_shs: Javascript settings for shs widgets.

string $bundle: Bundle name of vocabulary the settings are used for.

string $field_name: Name of field the provided settings are used for.

File

modules/shs_chosen/shs_chosen.module, line 30
Main functions for the "Simple hierarchical select: Chosen" module.

Code

function shs_chosen_shs_js_settings_alter(array &$settings_shs, $bundle, $field_name) {
  if (!isset($settings_shs['settings']['chosen_override']) || empty($settings_shs['settings']['chosen_settings'])) {
    return;
  }
  $chosen_conf = Drupal::config('chosen.settings')
    ->get();
  if ($settings_shs['settings']['chosen_override']) {
    $chosen_conf = $settings_shs['settings']['chosen_settings'] + $chosen_conf;
  }
  $settings_shs['display']['chosen'] = [
    'selector' => 'select.shs-select',
    'minimum_single' => 0,
    'minimum_multiple' => 0,
    'minimum_width' => (int) $chosen_conf['minimum_width'],
    'options' => [
      'disable_search' => (bool) $chosen_conf['disable_search'],
      'disable_search_threshold' => (int) $chosen_conf['disable_search_threshold'],
      'search_contains' => (bool) $chosen_conf['search_contains'],
      'placeholder_text_multiple' => $chosen_conf['placeholder_text_multiple'],
      'placeholder_text_single' => $chosen_conf['placeholder_text_single'],
      'no_results_text' => $chosen_conf['no_results_text'],
      'inherit_select_classes' => TRUE,
    ],
  ];
}