You are here

public function NodeRevisionGenerateForm::submitForm in Node Revision Delete 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

modules/node_revision_generate/src/Form/NodeRevisionGenerateForm.php, line 151

Class

NodeRevisionGenerateForm
Class NodeRevisionGenerate.

Namespace

Drupal\node_revision_generate\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // Get selected content types.
  $bundles = array_filter($form_state
    ->getValue('bundles'));

  // Get form values.
  $revisions_number = $form_state
    ->getValue('revisions_number');
  $interval_number = $form_state
    ->getValue('number');
  $interval_time = $form_state
    ->getValue('time');

  // Get interval to generate revisions.
  $revisions_age = $interval_number * $interval_time;

  // Get the available nodes to generate revisions.
  $nodes_for_revisions = $this->nodeRevisionGenerate
    ->getAvailableNodesForRevisions($bundles, $revisions_age);

  // Check if there is nodes to generate revisions.
  if ($nodes_for_revisions) {

    // Setting the batch.
    batch_set($this->nodeRevisionGenerate
      ->getRevisionCreationBatch($nodes_for_revisions, $revisions_number, $revisions_age));
  }
  else {
    $this
      ->messenger()
      ->addWarning($this
      ->t('There are not more available nodes to generate revisions of the selected content types and specified options.'));
  }
}