You are here

public function GathercontentContentImportConfirmForm::submitForm in GatherContent 8

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 GathercontentMultistepFormBase::submitForm

File

src/Form/GathercontentContentImportConfirmForm.php, line 103

Class

GathercontentContentImportConfirmForm
Class GathercontentContentImportConfirmForm.

Namespace

Drupal\gathercontent\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  if ($form_state
    ->getTriggeringElement()['#id'] === 'edit-submit') {
    $operation = GathercontentOperation::create(array(
      'type' => 'import',
    ));
    $operation
      ->save();
    $operations = array();
    $stack = array();
    $import_content = $this->store
      ->get('nodes');
    foreach ($import_content as $k => $value) {
      if ($this->store
        ->get('menu')[$value] && $this->store
        ->get('menu')[$value] != -1) {
        $parent_menu_item = $this->store
          ->get('menu')[$value] ? $this->store
          ->get('menu')[$value] : NULL;
        $operations[] = array(
          'gc_import_process',
          array(
            $value,
            $form_state
              ->getValue('status'),
            $operation
              ->uuid(),
            $parent_menu_item,
          ),
        );
        $stack[] = $value;
        unset($import_content[$k]);
      }
    }
    if (!empty($import_content)) {

      // Load all by project_id.
      $first = reset($import_content);
      $content_obj = new Content();
      $content = $content_obj
        ->getContent($first);
      $contents_source = $content_obj
        ->getContents($content->project_id);
      $content = array();
      foreach ($contents_source as $value) {
        $content[$value->id] = $value;
      }
      while (!empty($import_content)) {
        $current = reset($import_content);
        if (isset($stack[$content[$current]->parent_id])) {
          $parent_menu_item = 'node:' . $content[$current]->parent_id;
          $operations[] = array(
            'gathercontent_import_process',
            array(
              $current,
              $form_state
                ->getValue('status'),
              $operation
                ->uuid(),
              $parent_menu_item,
            ),
          );
          $stack[] = $current;
          array_shift($import_content);
        }
        else {
          array_shift($import_content);
          array_push($import_content, $current);
        }
      }
    }
    $batch = array(
      'title' => t('Importing content ...'),
      'operations' => $operations,
      'finished' => 'gathercontent_import_finished',
      'file' => drupal_get_path('module', 'gathercontent') . '/gathercontent.module',
      'init_message' => t('Import is starting ...'),
      'progress_message' => t('Processed @current out of @total.'),
      'error_message' => t('An error occurred during processing'),
    );
    batch_set($batch);
  }
  else {
  }
}