protected function Xls::extractHeaders in Excel Serialization 8
Extract the headers from the data array.
Parameters
array $data: The data array.
array $context: The context options array.
Return value
string[] An array of headers to be used.
2 calls to Xls::extractHeaders()
- Xls::encode in src/
Encoder/ Xls.php - Encodes data into the given format.
- Xls::setHeaders in src/
Encoder/ Xls.php - Set sheet headers.
File
- src/
Encoder/ Xls.php, line 298
Class
- Xls
- Adds XLS encoder support for the Serialization API.
Namespace
Drupal\xls_serialization\EncoderCode
protected function extractHeaders(array $data, array $context) {
$headers = [];
if ($first_row = reset($data)) {
if (isset($context['header'])) {
$headers = $context['header'];
}
elseif (isset($context['views_style_plugin'])) {
/** @var \Drupal\views\ViewExecutable $view */
$view = $context['views_style_plugin']->view;
$fields = $view->field;
foreach ($first_row as $key => $value) {
$headers[] = !empty($fields[$key]->options['label']) ? $fields[$key]->options['label'] : $key;
}
}
else {
$headers = array_keys($first_row);
}
}
return $headers;
}