You are here

function Numeric::render in Views (for Drupal 7) 8.3

Render the field.

Parameters

$values: The values retrieved from the database.

Overrides FieldPluginBase::render

2 calls to Numeric::render()
NodeNewComments::render in lib/Views/comment/Plugin/views/field/NodeNewComments.php
Render the field.
Score::render in lib/Views/search/Plugin/views/field/Score.php
Render the field.
2 methods override Numeric::render()
NodeNewComments::render in lib/Views/comment/Plugin/views/field/NodeNewComments.php
Render the field.
Score::render in lib/Views/search/Plugin/views/field/Score.php
Render the field.

File

lib/Drupal/views/Plugin/views/field/Numeric.php, line 129
Definition of Drupal\views\Plugin\views\field\Numeric.

Class

Numeric
Render a field as a numeric value

Namespace

Drupal\views\Plugin\views\field

Code

function render($values) {
  $value = $this
    ->get_value($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 '';
  }

  // Should we format as a plural.
  if (!empty($this->options['format_plural'])) {
    $value = format_plural($value, $this->options['format_plural_singular'], $this->options['format_plural_plural']);
  }
  return $this
    ->sanitizeValue($this->options['prefix'], 'xss') . $this
    ->sanitizeValue($value) . $this
    ->sanitizeValue($this->options['suffix'], 'xss');
}