You are here

public function MultipleNodeExportForm::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/MultipleNodeExportForm.php, line 50

Class

MultipleNodeExportForm
Provides a Node Export form.

Namespace

Drupal\node_Export\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $export_type = $form_state
    ->getValue('export_type');

  // Loads all the node of selected content type.
  $nids = \Drupal::entityQuery('node')
    ->condition('type', $export_type)
    ->execute();
  $batch = [
    'title' => $this
      ->t('Generating Export Code...'),
    'operations' => [],
    'init_message' => $this
      ->t('Exporting '),
    'progress_message' => $this
      ->t('Processed @current out of @total.'),
    'error_message' => $this
      ->t('An error occurred during processing'),
    'finished' => '\\Drupal\\node_export\\NodeExport::nodeExportFinishedCallback',
  ];
  if (!empty($nids)) {
    foreach ($nids as $nid) {
      $batch['operations'][] = [
        '\\Drupal\\node_export\\NodeExport::nodeExport',
        [
          $nid,
        ],
      ];
    }
    batch_set($batch);
    $this
      ->messenger()
      ->addStatus($this
      ->t('The File with export code has been saved in your public directory'));
  }
  else {
    $this
      ->messenger()
      ->addError($this
      ->t('There are no nodes to export.'));
  }
}