You are here

public function SpreadsheetIterator::getColumns in Migrate Spreadsheet 8

Same name and namespace in other branches
  1. 2.0.x src/SpreadsheetIterator.php \Drupal\migrate_spreadsheet\SpreadsheetIterator::getColumns()

Gets the list of columns.

Return value

string[] The list of columns.

Throws

\InvalidArgumentException If a column passed in 'columns' does not exist in the header.

Overrides SpreadsheetIteratorInterface::getColumns

See also

\Drupal\migrate_spreadsheet\SpreadsheetIteratorInterface::setColumns()

1 call to SpreadsheetIterator::getColumns()
SpreadsheetIterator::current in src/SpreadsheetIterator.php

File

src/SpreadsheetIterator.php, line 180

Class

SpreadsheetIterator
Provides a spreadsheet iterator.

Namespace

Drupal\migrate_spreadsheet

Code

public function getColumns() {
  if (!isset($this->cache['columns'])) {
    $headers = $this
      ->getHeaders();
    if (empty($this->configuration['columns'])) {

      // If no columns were passed, all columns will be used.
      $this->cache['columns'] = $headers;
    }
    else {
      $this->cache['columns'] = [];
      foreach ($this->configuration['columns'] as $column) {
        $column = trim($column);
        if (!isset($headers[$column])) {
          throw new \InvalidArgumentException("Column '{$column}' doesn't exist in the table header.");
        }
        $this->cache['columns'][$column] = $headers[$column];
      }
    }
  }
  return $this->cache['columns'];
}