You are here

public function ContentSync::submitForm in Content Synchronization 8.2

Same name and namespace in other branches
  1. 8 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 207

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
  $content_to_sync = [];
  $content_to_delete = [];
  foreach ($collections as $collection => $collection_name) {
    $actions = $comparer
      ->getChangeList("", $collection_name);
    if (!empty($actions['create'])) {
      $content_to_sync = array_merge($content_to_sync, $actions['create']);
    }
    if (!empty($actions['update'])) {
      $content_to_sync = array_merge($content_to_sync, $actions['update']);
    }
    if (!empty($actions['delete'])) {
      $content_to_delete = $actions['delete'];
    }
  }
  $serializer_context = [];
  $batch = $this
    ->generateImportBatch($content_to_sync, $content_to_delete, $serializer_context);
  batch_set($batch);
}