You are here

public function ContentHubExportQueueForm::submitForm in Acquia Content Hub 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 ConfigFormBase::submitForm

File

src/Form/ContentHubExportQueueForm.php, line 200

Class

ContentHubExportQueueForm
Implements a form to Process items from the Content Hub Export Queue.

Namespace

Drupal\acquia_contenthub\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $queue_count = intval($this->exportQueueController
    ->getQueueCount());
  $trigger = $form_state
    ->getTriggeringElement();
  switch ($trigger['#name']) {
    case 'run_export_queue':
      if (!empty($queue_count)) {
        $number_of_items = $form_state
          ->getValues()['number_of_items'];
        $this->exportQueueController
          ->processQueueItems($number_of_items);
      }
      else {
        $this
          ->messenger()
          ->addWarning($this
          ->t('You cannot run the export queue because it is empty.'));
      }
      break;
    case 'purge_export_queue':
      $this->exportQueueController
        ->purgeQueue();
      $this
        ->messenger()
        ->addStatus($this
        ->t("Purged all contenthub export queues."));
      break;
    default:
      $config = $this->configFactory
        ->getEditable('acquia_contenthub.entity_config');
      $export_with_queue = $form_state
        ->getValue('export_with_queue');
      $export_queue_entities_per_item = $form_state
        ->getValue('entities_per_item');
      $export_queue_batch_size = $form_state
        ->getValue('batch_size');
      $export_queue_waiting_time = $form_state
        ->getValue('waiting_time');
      $config
        ->set('export_with_queue', $export_with_queue);
      $config
        ->set('export_queue_entities_per_item', $export_queue_entities_per_item);
      $config
        ->set('export_queue_batch_size', $export_queue_batch_size);
      $config
        ->set('export_queue_waiting_time', $export_queue_waiting_time);
      $config
        ->save();
      break;
  }
}