public function DataExport::render in Views data export 8
Render the display in this style.
Overrides Serializer::render
File
- src/
Plugin/ views/ style/ DataExport.php, line 233
Class
- DataExport
- A style plugin for data export views.
Namespace
Drupal\views_data_export\Plugin\views\styleCode
public function render() {
// This is pretty close to the parent implementation.
// Difference (noted below) stems from not being able to get anything other
// than json rendered even when the display was set to export csv or xml.
$rows = [];
foreach ($this->view->result as $row_index => $row) {
$this->view->row_index = $row_index;
$rows[] = $this->view->rowPlugin
->render($row);
}
unset($this->view->row_index);
// Get the format configured in the display or fallback to json.
// We intentionally implement this different from the parent method because
// $this->displayHandler->getContentType() will always return json due to
// the request's header (i.e. "accept:application/json") and
// we want to be able to render csv or xml data as well in accordance with
// the data export format configured in the display.
$format = !empty($this->options['formats']) ? reset($this->options['formats']) : 'json';
// If data is being exported as a CSV we give the option to not use the
// Symfony normalize method which increases performance on large data sets.
// This option can be configured in the CSV Settings section of the data
// export.
if ($format === 'csv' && $this->options['csv_settings']['use_serializer_encode_only'] == 1) {
return $this->serializer
->encode($rows, $format, [
'views_style_plugin' => $this,
]);
}
else {
return $this->serializer
->serialize($rows, $format, [
'views_style_plugin' => $this,
]);
}
}