You are here

public function SourceCsvForm::submitForm in Migrate Tools 8.4

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

src/Form/SourceCsvForm.php, line 310

Class

SourceCsvForm
Provides an edit form for CSV source plugin column_names configuration.

Namespace

Drupal\migrate_tools\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // Create a new column_names configuration.
  $new_column_names = [];
  foreach ($this->columnNames as $index => $data) {

    // Keep the property name as it is used in the process pipeline.
    $property_name = key($data);

    // Get the new column number from the form alias field for this property.
    $new_index = $form_state
      ->getValue($property_name);

    // Get the new label from the options array.
    $new_label = $this->options[$new_index];

    // Save using the new column number and new label.
    $new_column_names[$new_index] = [
      $property_name => $new_label,
    ];
  }

  // Update the file columns.
  $this->file
    ->setColumnNames($new_column_names);

  // Save as updated in the store.
  $this->sourceConfiguration['changed'] = $new_column_names;
  $this->store
    ->set($this->id, $this->sourceConfiguration);
  $changed = $this->store
    ->get('migrations_changed') ? $this->store
    ->get('migrations_changed') : [];
  if (!in_array($this->id, $changed)) {
    $changed[] = $this->id;
    $this->store
      ->set('migrations_changed', $changed);
  }
}