You are here

public function ConfigForm::submitForm in Flysystem 8

Same name and namespace in other branches
  1. 3.x src/Form/ConfigForm.php \Drupal\flysystem\Form\ConfigForm::submitForm()
  2. 2.0.x src/Form/ConfigForm.php \Drupal\flysystem\Form\ConfigForm::submitForm()
  3. 3.0.x src/Form/ConfigForm.php \Drupal\flysystem\Form\ConfigForm::submitForm()

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/ConfigForm.php, line 96

Class

ConfigForm
Configure file system settings for this site.

Namespace

Drupal\flysystem\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $scheme_from = $form_state
    ->getValue('sync_from');
  $scheme_to = $form_state
    ->getValue('sync_to');
  $from_files = $this
    ->getFileList($scheme_from);
  $to_files = [];
  if (!$form_state
    ->getValue('force')) {
    $to_files = $this
      ->getFileList($scheme_to);
  }
  $batch = [
    'operations' => [],
    'finished' => get_class($this) . '::finishBatch',
    'title' => $this
      ->t('Synchronizing file systems'),
    'init_message' => $this
      ->t('Starting file system synchronization.'),
    'progress_message' => $this
      ->t('Completed @current step of @total.'),
    'error_message' => $this
      ->t('File system synchronization has encountered an error.'),
  ];

  // @todo We shouldn't do all files in one go, but rather add files and
  // directories and recurse in a batch callback.
  foreach (array_diff($from_files, $to_files) as $filepath) {
    $batch['operations'][] = [
      get_class($this) . '::copyFile',
      [
        $scheme_from,
        $scheme_to,
        $filepath,
      ],
    ];
  }
  batch_set($batch);
}