protected function DurationHumanDisplayFormatter::getHumanFriendlyLabel in Duration Field 8
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldFormatter/DurationHumanDisplayFormatter.php \Drupal\duration_field\Plugin\Field\FieldFormatter\DurationHumanDisplayFormatter::getHumanFriendlyLabel()
- 3.0.x src/Plugin/Field/FieldFormatter/DurationHumanDisplayFormatter.php \Drupal\duration_field\Plugin\Field\FieldFormatter\DurationHumanDisplayFormatter::getHumanFriendlyLabel()
Converts a key to a human readable value.
Parameters
string $key: The machine readable name to be converted.
bool $capitalize: Whether or not the return value should be capitalized.
Return value
string The converted value, if a mapping exists, otherwise the original key
2 calls to DurationHumanDisplayFormatter::getHumanFriendlyLabel()
- DurationHumanDisplayFormatter::settingsForm in src/
Plugin/ Field/ FieldFormatter/ DurationHumanDisplayFormatter.php - Returns a form to configure settings for the formatter.
- DurationHumanDisplayFormatter::settingsSummary in src/
Plugin/ Field/ FieldFormatter/ DurationHumanDisplayFormatter.php - Returns a short summary for the current formatter settings.
File
- src/
Plugin/ Field/ FieldFormatter/ DurationHumanDisplayFormatter.php, line 209
Class
- DurationHumanDisplayFormatter
- Provides a formatter for the duration field type.
Namespace
Drupal\duration_field\Plugin\Field\FieldFormatterCode
protected function getHumanFriendlyLabel($key, $capitalize = TRUE) {
$custom_labels = $this->moduleHandler
->invokeAll('duration_field_labels');
if (!isset($custom_labels['capitalized'])) {
$custom_labels['capitalized'] = [];
}
if (!isset($custom_labels['lowercase'])) {
$custom_labels['lowercase'] = [];
}
if ($capitalize) {
$values = [
'full' => t('Full'),
'short' => t('Short'),
'space' => t('Spaces'),
'hyphen' => t('Hyphens'),
'comma' => t('Commas'),
'newline' => t('New lines'),
] + $custom_labels['capitalized'];
}
else {
$values = [
'full' => t('full'),
'short' => t('short'),
'space' => t('spaces'),
'hyphen' => t('hyphens'),
'comma' => t('commas'),
'newline' => t('new lines'),
] + $custom_labels['lowercase'];
}
return isset($values[$key]) ? $values[$key] : $key;
}