You are here

public function TimeFieldFormatter::settingsSummary in Time Formatter 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Field/FieldFormatter/TimeFieldFormatter.php \Drupal\time_formatter\Plugin\Field\FieldFormatter\TimeFieldFormatter::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/TimeFieldFormatter.php, line 122

Class

TimeFieldFormatter
Plugin implementation of the 'time_field_formatter' formatter.

Namespace

Drupal\time_formatter\Plugin\Field\FieldFormatter

Code

public function settingsSummary() {
  $summary = [];
  switch ($this
    ->getSetting('storage')) {
    case self::STORAGE_SECONDS:
      $summary['storage'] = $this
        ->t('Storage: Seconds');
      break;
    case self::STORAGE_MILLISECONDS:
      $summary['storage'] = $this
        ->t('Storage: Milliseconds');
      break;
  }
  switch ($this
    ->getSetting('display')) {
    case self::DISPLAY_HMSMS:
      $summary['display'] = $this
        ->t('Display: 123h 59m 59s 999ms');
      break;
    case self::DISPLAY_HMS:
      $summary['display'] = $this
        ->t('Display: 123h 59m 59s');
      break;
    case self::DISPLAY_NUMBERSMS:
      $summary['display'] = $this
        ->t('Display: 123:59:59.999');
      break;
    case self::DISPLAY_NUMBERS:
      $summary['display'] = $this
        ->t('Display: 123:59:59');
      break;
  }
  switch ($this
    ->getSetting('hours')) {
    case self::HOURS_ALWAYS:
      $summary['hours'] = $this
        ->t('Display hours: Always');
      break;
    case self::HOURS_OPTIONAL:
      $summary['hours'] = $this
        ->t('Display hours: Optional');
      break;
    case self::HOURS_NEVER:
      $summary['hours'] = $this
        ->t('Display hours: Never');
      break;
  }
  return $summary;
}