You are here

public function CSV::fields in Migrate Source CSV 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/migrate/source/CSV.php \Drupal\migrate_source_csv\Plugin\migrate\source\CSV::fields()
  2. 8 src/Plugin/migrate/source/CSV.php \Drupal\migrate_source_csv\Plugin\migrate\source\CSV::fields()

Returns available fields on the source.

Return value

array Available fields in the source, keys are the field machine names as used in field mappings, values are descriptions.

Overrides MigrateSourceInterface::fields

File

src/Plugin/migrate/source/CSV.php, line 154

Class

CSV
Source for CSV.

Namespace

Drupal\migrate_source_csv\Plugin\migrate\source

Code

public function fields() {
  $fields = [];
  if (!$this->file) {
    $this
      ->initializeIterator();
  }
  foreach ($this->file
    ->getColumnNames() as $column) {
    $fields[key($column)] = reset($column);
  }

  // Any caller-specified fields with the same names as extracted fields will
  // override them; any others will be added.
  $fields = $this
    ->getConfiguration()['fields'] + $fields;
  return $fields;
}