You are here

public function CSV::fields in Migrate Source CSV 8.3

Same name and namespace in other branches
  1. 8 src/Plugin/migrate/source/CSV.php \Drupal\migrate_source_csv\Plugin\migrate\source\CSV::fields()
  2. 8.2 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

1 call to CSV::fields()
CSV::initializeIterator in src/Plugin/migrate/source/CSV.php

File

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

Class

CSV
Source for CSV files.

Namespace

Drupal\migrate_source_csv\Plugin\migrate\source

Code

public function fields() {

  // If fields are not defined, use the header record.
  if (empty($this->configuration['fields'])) {
    $header = $this
      ->getReader()
      ->getHeader();
    return array_combine($header, $header);
  }
  $fields = [];
  foreach ($this->configuration['fields'] as $field) {
    $fields[$field['name']] = isset($field['label']) ? $field['label'] : $field['name'];
  }
  return $fields;
}