You are here

function field_label_field_formatter_settings_summary_alter in Field Label 8

Implements hook_field_formatter_settings_summary_alter().

File

./field_label.module, line 29
Provides custom settings to format field labels.

Code

function field_label_field_formatter_settings_summary_alter(&$summary, $context) {

  // Load formatter settings and module config.
  $settings = $context['formatter']
    ->getThirdPartySettings('field_label');
  $config = \Drupal::config('field_label.settings');
  if ($settings) {
    if ($config
      ->get('label_value_enabled') && !empty($settings['label_value'])) {
      $summary[] = t('Label: @label', [
        '@label' => $settings['label_value'],
      ]);
    }
    if ($config
      ->get('label_class_select_enabled') && !empty($settings['label_class_select'])) {
      $selected_style = $settings['label_class_select'];

      // Ensure the selected style is still valid.
      if ($valid_style = _field_label_is_valid_style($selected_style)) {
        $summary[] = t('Label class: @class', [
          '@class' => $valid_style['label'],
        ]);
      }
    }
    if ($config
      ->get('label_class_enabled') && !empty($settings['label_class'])) {
      $summary[] = t('Extra label classes: @class', [
        '@class' => $settings['label_class'],
      ]);
    }
    if ($config
      ->get('label_tag_enabled') && !empty($settings['label_tag'])) {
      $summary[] = t('Label wrapper: @tag', [
        '@tag' => $settings['label_tag'],
      ]);
    }
  }
}