You are here

public function NodeImportForm::submitForm in Node export 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 FormInterface::submitForm

File

src/Form/NodeImportForm.php, line 51

Class

NodeImportForm
Provides a Node Import form.

Namespace

Drupal\node_Export\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $json = $form_state
    ->getValue('paste');
  $nodes = json_decode($json, TRUE);
  $batch = [
    'title' => $this
      ->t('Importing Nodes...'),
    'operations' => [],
    'init_message' => $this
      ->t('Imporitng'),
    'progress_message' => $this
      ->t('Processed @current out of @total.'),
    'error_message' => $this
      ->t('An error occurred during processing'),
    'finished' => '\\Drupal\\node_export\\NodeImport::nodeImportFinishedCallback',
  ];
  foreach ($nodes as $node) {
    $batch['operations'][] = [
      '\\Drupal\\node_export\\NodeImport::nodeImport',
      [
        $node,
      ],
    ];
  }
  batch_set($batch);
  $this
    ->messenger()
    ->addStatus($this
    ->t('Node has been imported succesfully.'));
}