public function SpreadsheetIterator::key in Migrate Spreadsheet 8
Same name and namespace in other branches
- 2.0.x src/SpreadsheetIterator.php \Drupal\migrate_spreadsheet\SpreadsheetIterator::key()
File
- src/
SpreadsheetIterator.php, line 44
Class
- SpreadsheetIterator
- Provides a spreadsheet iterator.
Namespace
Drupal\migrate_spreadsheetCode
public function key() {
if (empty($keys = $this
->getKeys())) {
// If no keys were passed, use the spreadsheet current row position.
if (!$this
->getRowIndexColumn()) {
throw new \RuntimeException("Row index should act as key but no name has been provided. Use SpreadsheetIterator::setRowIndexColumn() to provide a name for this column.");
}
return [
$this
->getAbsoluteRowIndex(),
];
}
return array_values(array_map(function ($col_letter) {
$cell_reference = "{$col_letter}{$this->getAbsoluteRowIndex()}";
if ($cell = $this
->getWorksheet()
->getCell($cell_reference, FALSE)) {
return $cell
->getValue();
}
$key = array_search($col_letter, $this
->getKeys());
throw new \RuntimeException("Key column '{$key}' contains a null value at {$cell_reference}.");
}, $keys));
}