You are here

public function ContentSync::submitForm in Content Synchronization 8

Same name and namespace in other branches
  1. 8.2 src/Form/ContentSync.php \Drupal\content_sync\Form\ContentSync::submitForm()
  2. 3.0.x src/Form/ContentSync.php \Drupal\content_sync\Form\ContentSync::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/ContentSync.php, line 301

Class

ContentSync
Construct the storage changes in a content synchronization form.

Namespace

Drupal\content_sync\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $comparer = $form_state
    ->get('storage_comparer');
  $collections = $comparer
    ->getAllCollectionNames();

  //Set Batch to process the files from the content directory.

  //Get the files to be processed
  $operations = [];
  foreach ($collections as $collection => $collection_name) {
    $actions = $comparer
      ->getChangeList("", $collection_name);
    foreach ($actions as $operation => $files) {
      if (!empty($files)) {
        $operations[] = [
          'processContentDirectoryBatch',
          [
            $files,
            $collection_name,
            $operation,
          ],
        ];
      }
    }
  }
  foreach ($collections as $collection => $collection_name) {
    $actions = $comparer
      ->getChangeList("", $collection_name);
    foreach ($actions as $operation => $files) {
      if (!empty($files)) {
        $operations[] = [
          'processContentDirectoryBatch',
          [
            $files,
            $collection_name,
            $operation,
          ],
        ];
      }
    }
  }
  $batch = [
    'operations' => $operations,
    'finished' => 'finishContentBatch',
    'title' => $this
      ->t('Importing content'),
    'init_message' => $this
      ->t('Starting content import.'),
    'progress_message' => $this
      ->t('Completed @current step of @total.'),
    'error_message' => $this
      ->t('Content import has encountered an error.'),
    'file' => drupal_get_path('module', 'content_sync') . '/content_sync.batch.inc',
  ];
  batch_set($batch);
}