public function NumericField::render in Drupal 10
Same name and namespace in other branches
- 8 core/modules/views/src/Plugin/views/field/NumericField.php \Drupal\views\Plugin\views\field\NumericField::render()
- 9 core/modules/views/src/Plugin/views/field/NumericField.php \Drupal\views\Plugin\views\field\NumericField::render()
1 call to NumericField::render()
- NodeNewComments::render in core/modules/comment/src/Plugin/views/field/NodeNewComments.php
2 methods override NumericField::render()
- NodeNewComments::render in core/modules/comment/src/Plugin/views/field/NodeNewComments.php
- Score::render in core/modules/search/src/Plugin/views/field/Score.php
File
- core/modules/views/src/Plugin/views/field/NumericField.php, line 151
Class
- NumericField
- Render a field as a numeric value.
Namespace
Drupal\views\Plugin\views\field
Code
public function render(ResultRow $values) {
$value = $this
->getValue($values);
if ($this->options['hide_empty'] && empty($value) && ($value !== 0 || $this->options['empty_zero'])) {
return '';
}
$value = $value ?? 0;
if (!empty($this->options['set_precision'])) {
$precision = $this->options['precision'];
}
elseif ($decimal_position = strpos($value, '.')) {
$precision = strlen($value) - $decimal_position - 1;
}
else {
$precision = 0;
}
$value = round($value, $precision);
if ($this->options['empty_zero'] && ($value === 0 || $value === 0.0)) {
return '';
}
$value = number_format($value, $precision, $this->options['decimal'], $this->options['separator']);
if (!empty($this->options['format_plural'])) {
$value = PluralTranslatableMarkup::createFromTranslatedString($value, $this->options['format_plural_string']);
}
return $this
->sanitizeValue($this->options['prefix'], 'xss') . $this
->sanitizeValue($value) . $this
->sanitizeValue($this->options['suffix'], 'xss');
}