public function GeneralNumberFormatter::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
1 call to GeneralNumberFormatter::settingsSummary()
- GeneralNumberWithBarIndicatorFormatter::settingsSummary in src/
Plugin/ Field/ FieldFormatter/ GeneralNumberWithBarIndicatorFormatter.php - Returns a short summary for the current formatter settings.
2 methods override GeneralNumberFormatter::settingsSummary()
- GeneralNumberWithBarIndicatorFormatter::settingsSummary in src/
Plugin/ Field/ FieldFormatter/ GeneralNumberWithBarIndicatorFormatter.php - Returns a short summary for the current formatter settings.
- GeneralNumberWithMinMaxFormatter::settingsSummary in src/
Plugin/ Field/ FieldFormatter/ GeneralNumberWithMinMaxFormatter.php - Returns a short summary for the current formatter settings.
File
- src/
Plugin/ Field/ FieldFormatter/ GeneralNumberFormatter.php, line 207
Class
- GeneralNumberFormatter
- Format a number field with a variety of notation styles and parameters.
Namespace
Drupal\formatter_suite\Plugin\Field\FieldFormatterCode
public function settingsSummary() {
// Sanitize and get current settings.
$this
->sanitizeSettings();
$isMultiple = $this->fieldDefinition
->getFieldStorageDefinition()
->isMultiple();
// Summarize.
$summary = [];
$fieldType = $this->fieldDefinition
->getType();
if ($fieldType === 'integer') {
$sample = -1234;
}
else {
$sample = -1234.56789;
}
// Formatting a number can introduced HTML. To preserve it during
// presentation, call it formatted markup.
$value = $this
->numberFormat($sample);
$value = new FormattableMarkup($value, []);
$summary[] = $this
->t('Sample: @value', [
'@value' => $value,
]);
// If the field can store multiple values, then summarize list style.
if ($isMultiple === TRUE) {
$listStyles = $this
->getListStyles();
$listStyle = $this
->getSetting('listStyle');
$listSeparator = $this
->getSetting('listSeparator');
$text = $listStyles[$listStyle];
if ($listStyle === 'span' && empty($listSeparator) === FALSE) {
$text .= $this
->t(', with separator');
}
$summary[] = $text;
}
return $summary;
}