public function NumericField::render in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/views/src/Plugin/views/field/NumericField.php \Drupal\views\Plugin\views\field\NumericField::render()
Renders the field.
Parameters
\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.
Return value
string|\Drupal\Component\Render\MarkupInterface The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.
Overrides FieldPluginBase::render
2 calls to NumericField::render()
- NodeNewComments::render in core/
modules/ comment/ src/ Plugin/ views/ field/ NodeNewComments.php - Renders the field.
- Score::render in core/
modules/ search/ src/ Plugin/ views/ field/ Score.php - Renders the field.
2 methods override NumericField::render()
- NodeNewComments::render in core/
modules/ comment/ src/ Plugin/ views/ field/ NodeNewComments.php - Renders the field.
- Score::render in core/
modules/ search/ src/ Plugin/ views/ field/ Score.php - Renders the field.
File
- core/
modules/ views/ src/ Plugin/ views/ field/ NumericField.php, line 155 - Contains \Drupal\views\Plugin\views\field\NumericField.
Class
- NumericField
- Render a field as a numeric value
Namespace
Drupal\views\Plugin\views\fieldCode
public function render(ResultRow $values) {
$value = $this
->getValue($values);
if (!empty($this->options['set_precision'])) {
$value = number_format($value, $this->options['precision'], $this->options['decimal'], $this->options['separator']);
}
else {
$remainder = abs($value) - intval(abs($value));
$value = $value > 0 ? floor($value) : ceil($value);
$value = number_format($value, 0, '', $this->options['separator']);
if ($remainder) {
// The substr may not be locale safe.
$value .= $this->options['decimal'] . substr($remainder, 2);
}
}
// Check to see if hiding should happen before adding prefix and suffix.
if ($this->options['hide_empty'] && empty($value) && ($value !== 0 || $this->options['empty_zero'])) {
return '';
}
// If we should format as plural, take the (possibly) translated plural
// setting and format with the current language.
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');
}