You are here

public function NumberWithBytesFormatter::settingsSummary in Formatter Suite 8

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/NumberWithBytesFormatter.php, line 65

Class

NumberWithBytesFormatter
Formats numbers with a byte suffix, like "bytes", "KB", or "MB".

Namespace

Drupal\formatter_suite\Plugin\Field\FieldFormatter

Code

public function settingsSummary() {
  $this
    ->sanitizeSettings();
  $summary = [];
  $summary[] = $this
    ->t('Sample: @value', [
    '@value' => Utilities::formatBytes(1289748, $this
      ->getSetting('kunit'), $this
      ->getSetting('fullWord'), $this
      ->getSetting('decimalDigits')),
  ]);
  switch ($this
    ->getSetting('kunit')) {
    default:
    case 1000:
      if ($this
        ->getSetting('fullWord') === FALSE) {
        $summary[] = $this
          ->t('KB, MB, GB, etc.');
      }
      else {
        $summary[] = $this
          ->t('Kilobyte, Megabyte, Gigabyte, etc.');
      }
      break;
    case 1024:
      if ($this
        ->getSetting('fullWord') === FALSE) {
        $summary[] = $this
          ->t('KiB, MiB, GiB, etc.');
      }
      else {
        $summary[] = $this
          ->t('Kibibyte, Mebibyte, Gibibyte, etc.');
      }
      break;
  }
  return $summary;
}