You are here

function select2boxes_field_widget_settings_summary_alter in Select2 Boxes 8

Implements hook_field_widget_settings_summary_alter().

File

./select2boxes.module, line 135
Basic module file.

Code

function select2boxes_field_widget_settings_summary_alter(&$summary, $context) {

  // Add content to the summary to allow users to see all custom options status.

  /** @var \Drupal\Core\Field\WidgetInterface $widget */
  $widget = $context['widget'];
  $settings = $widget
    ->getThirdPartySettings('select2boxes');
  if ($widget
    ->getPluginId() == 'select2boxes_autocomplete_multi') {
    if (!empty($settings) && $settings['enable_preload'] == '1') {
      $count = $settings['preload_count'] || $settings['preload_count'] == '0' ? $settings['preload_count'] : 'all';
      $summary[] = t('Number of preloaded entries: @count', [
        '@count' => $count,
      ]);
    }
    else {
      $summary[] = t('Preloading disabled');
    }
  }
  elseif ($widget
    ->getPluginId() == 'select2boxes_autocomplete_list' || $widget
    ->getPluginId() == 'select2boxes_autocomplete_single') {

    /** @var \Drupal\field\Entity\FieldConfig $definition */
    $definition = $context['field_definition'];
    $flag_types = [
      'language_field',
      'language',
      'country',
    ];
    if (in_array($definition
      ->getType(), $flag_types) && \Drupal::moduleHandler()
      ->moduleExists('flags')) {
      if (!empty($settings) && $settings['enable_flags'] == '1') {
        $summary[] = t('Flags icons enabled');
      }
      else {
        $summary[] = t('Flags icons disabled');
      }
    }
  }
  elseif (in_array($widget
    ->getPluginId(), _select2boxes_address_widgets_list())) {
    if (!empty($settings) && $settings['enable_select2'] == '1') {
      $summary[] = t('Select2 enabled');
    }
    else {
      $summary[] = t('Select2 disabled');
    }
  }
}