public function CsvFileObject::current in Commerce Pricelist 8.2
1 call to CsvFileObject::current()
- CsvFileObject::__construct in src/
CsvFileObject.php - Constructs a new CsvFileObject object.
File
- src/
CsvFileObject.php, line 79
Class
- CsvFileObject
- Defines a wrapper around CSV data in a file.
Namespace
Drupal\commerce_pricelistCode
public function current() {
$row = parent::current();
if (!$row) {
// Invalid row, stop here.
return $row;
}
if ($this->hasHeader && $this
->key() === 0) {
// Only data rows can be remapped.
return $row;
}
$remapped_row = [];
foreach ($row as $key => $value) {
$new_key = $key;
// Use the column name from the header as the default key.
if ($this->hasHeader) {
$new_key = trim($this->header[$key]);
}
// Map the selected key to the desired one, if any.
if (isset($this->headerMapping[$new_key])) {
$new_key = $this->headerMapping[$new_key];
}
$remapped_row[$new_key] = $value;
}
return $remapped_row;
}