You are here

public function MigrateSourceUiForm::buildForm in Migrate source UI 8

Form constructor.

Parameters

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

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

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/MigrateSourceUiForm.php, line 88

Class

MigrateSourceUiForm
Contribute form.

Namespace

Drupal\migrate_source_ui\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $options = [];
  foreach ($this->definitions as $definition) {
    $migrationInstance = $this->pluginManagerMigration
      ->createStubMigration($definition);
    if ($migrationInstance
      ->getSourcePlugin() instanceof CSV || $migrationInstance
      ->getSourcePlugin() instanceof Json || $migrationInstance
      ->getSourcePlugin() instanceof Xml) {
      $id = $definition['id'];
      $options[$id] = $this
        ->t('%id (supports %file_type)', [
        '%id' => $definition['label'] ?? $id,
        '%file_type' => $this
          ->getFileExtensionSupported($migrationInstance),
      ]);
    }
  }
  $form['migrations'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Migrations'),
    '#options' => $options,
  ];
  $form['source_file'] = [
    '#type' => 'file',
    '#title' => $this
      ->t('Upload the source file'),
  ];
  $form['update_existing_records'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Update existing records'),
    '#default_value' => 1,
  ];
  $form['import'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Migrate'),
  ];
  return $form;
}