public static function Util::viewsData in Charts 5.0.x
Same name and namespace in other branches
- 8.4 src/Util/Util.php \Drupal\charts\Util\Util::viewsData()
- 8 src/Util/Util.php \Drupal\charts\Util\Util::viewsData()
- 8.3 src/Util/Util.php \Drupal\charts\Util\Util::viewsData()
Views Data.
Parameters
\Drupal\views\ViewExecutable $view: View.
array $labelValues: Label Values.
string $labelField: Label Field.
array $color: Colors.
string|null $attachmentChartTypeOption: Attachment Chart Type Option.
Return value
array Data.
File
- src/
Util/ Util.php, line 29
Class
- Util
- Util.
Namespace
Drupal\charts\UtilCode
public static function viewsData(ViewExecutable $view = NULL, array $labelValues = [], $labelField = '', array $color = [], $attachmentChartTypeOption = NULL) {
$data = [];
$style_options = $view
->getStyle()->options['chart_settings'];
foreach ($view->result as $row_number => $row) {
$view->row_index = $row->index;
$numberFields = 0;
$rowData = [];
foreach ($labelValues as $fieldId => $rowDataValue) {
if ($style_options['fields']['allow_advanced_rendering'] == 1 || isset($view->field[$labelField]->options['type']) && $view->field[$labelField]->options['type'] === 'timestamp') {
$renderedLabelField = $view->field[$labelField]
->advancedRender($row);
}
else {
$renderedLabelField = $view->field[$labelField]
->getValue($row);
}
$renderedLabelField = strip_tags($renderedLabelField);
$rowData[$numberFields] = [
'value' => $style_options['fields']['allow_advanced_rendering'] ? $view->field[$fieldId]
->advancedRender($row) : $view->field[$fieldId]
->getValue($row),
'label_field' => $renderedLabelField,
'label' => $view->field[$fieldId]
->label(),
'color' => $color[$fieldId]['color'],
'type' => $attachmentChartTypeOption,
];
$numberFields++;
}
$data[$row_number] = $rowData;
}
return $data;
}