You are here

public function AgeFieldFormatter::settingsSummary in Age Field Formatter 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldFormatter/AgeFieldFormatter.php \Drupal\age_field_formatter\Plugin\Field\FieldFormatter\AgeFieldFormatter::settingsSummary()
  2. 3.0.x src/Plugin/Field/FieldFormatter/AgeFieldFormatter.php \Drupal\age_field_formatter\Plugin\Field\FieldFormatter\AgeFieldFormatter::settingsSummary()

Returns a short summary for the current formatter settings.

If an empty result is returned, a UI can still be provided to display a settings form in case the formatter has configurable settings.

Return value

string[] A short summary of the formatter settings.

Overrides FormatterBase::settingsSummary

File

src/Plugin/Field/FieldFormatter/AgeFieldFormatter.php, line 67

Class

AgeFieldFormatter
Plugin implementation of the 'age_field_formatter' formatter.

Namespace

Drupal\age_field_formatter\Plugin\Field\FieldFormatter

Code

public function settingsSummary() {
  $summary = [];

  // Implement settings summary.
  $setting = $this
    ->getSetting('age_format');
  $year_suffix = $this
    ->getSetting('year_suffix');
  $year_suffix_summary = $this
    ->t('years suffix');
  if ($setting == 'age_only') {
    $format = $this
      ->t('age only');
  }
  elseif ($setting == 'birthdate_nolabel') {
    $format = $this
      ->t('date (age)');
  }
  else {
    $format = $this
      ->t('date (age: xx)');
  }
  if ($year_suffix == true) {
    $format = $format . ' + ' . $year_suffix_summary;
  }
  $summary[] = $this
    ->t('Age format: %format', array(
    '%format' => $format,
  ));
  return $summary;
}