You are here

public function DepthUpdateForm::submitForm in Taxonomy Term Depth 8.2

Same name and namespace in other branches
  1. 8 src/Form/DepthUpdateForm.php \Drupal\taxonomy_term_depth\Form\DepthUpdateForm::submitForm()

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/DepthUpdateForm.php, line 130

Class

DepthUpdateForm

Namespace

Drupal\taxonomy_term_depth\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $identity = isset($form_state
    ->getTriggeringElement()['#identity']) ? $form_state
    ->getTriggeringElement()['#identity'] : 'unknown';
  $options = [];
  $options['vids'] = $form_state
    ->getValue('vid');
  switch ($identity) {
    case 'btn_rebuild_all_voc':

      // Apply "btn_rebuild_all" to all vocabularies
      $options['vids'] = NULL;
    case 'btn_rebuild_all':
      batch_set([
        'operations' => [
          [
            'taxonomy_term_depth_batch_callbacks_update_term_depth',
            [
              $options,
            ],
          ],
        ],
        'title' => $this
          ->t('Updating depths for all terms'),
        'file' => TAXONOMY_TERM_DEPTH_ROOT_REL . '/taxonomy_term_depth.batch.inc',
      ]);
      break;
    case 'btn_rebuild_all_voc_queue':
      taxonomy_term_depth_queue_manager()
        ->queueBatch();
      break;
    case 'btn_rebuild_all_queue':
      taxonomy_term_depth_queue_manager($options['vids'])
        ->queueBatch();
      break;
    case 'btn_rebuild_missing_all_voc_queue':
      taxonomy_term_depth_queue_manager()
        ->queueBatchMissing();
      break;
    case 'btn_rebuild_missing_queue':
      taxonomy_term_depth_queue_manager($options['vids'])
        ->queueBatchMissing();
      break;
    default:
      $this
        ->messenger()
        ->addMessage($this
        ->t('Wrong operation selected'));
  }
}