private function ChartsPluginStyleChart::processNumberValueFromField in Charts 5.0.x
Same name and namespace in other branches
- 8.4 src/Plugin/views/style/ChartsPluginStyleChart.php \Drupal\charts\Plugin\views\style\ChartsPluginStyleChart::processNumberValueFromField()
Processes number value based on field.
Parameters
int $number: The number.
string $field: The field.
Return value
\Drupal\Component\Render\MarkupInterface|float|null The value.
1 call to ChartsPluginStyleChart::processNumberValueFromField()
- ChartsPluginStyleChart::render in src/
Plugin/ views/ style/ ChartsPluginStyleChart.php - Render the display in this style.
File
- src/
Plugin/ views/ style/ ChartsPluginStyleChart.php, line 500
Class
- ChartsPluginStyleChart
- Style plugin to render view as a chart.
Namespace
Drupal\charts\Plugin\views\styleCode
private function processNumberValueFromField($number, $field) {
if (is_array($this
->getField($number, $field))) {
$value = $this
->getField($number, $field)
->__toString();
}
else {
$value = $this
->getField($number, $field);
}
if (\Drupal::service('twig')
->isDebug()) {
$value = trim(strip_tags($value));
}
if (strpos($field, 'field_charts_fields_scatter') === 0) {
return Json::decode($value);
}
// Convert empty strings to NULL.
if ($value === '' || is_null($value)) {
$value = NULL;
}
else {
// Strip thousands placeholders if present, then cast to float.
$value = (double) str_replace([
',',
' ',
], '', $value);
}
return $value;
}