TaxonomyDeleteUIForm.php in Taxonomy Delete 8
File
src/Form/TaxonomyDeleteUIForm.php
View source
<?php
namespace Drupal\taxonomy_delete\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
class TaxonomyDeleteUIForm extends FormBase {
public function getFormId() {
return 'taxonomy_delete_ui_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$vocabulary = [];
$vocabulary_items = taxonomy_vocabulary_get_names();
foreach ($vocabulary_items as $item) {
$vocabulary[$item] = ucfirst(str_replace("_", " ", $item));
}
$form['vocabulary'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Vocabularies'),
'#options' => $vocabulary,
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Delete Terms'),
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$selected_vocabulary = array_filter($form_state
->getValue('vocabulary'));
foreach ($selected_vocabulary as $vid) {
$batch = [
'operations' => [
[
'\\Drupal\\taxonomy_delete\\TaxonomyDeleteBatch::processVocabulary',
[
$vid,
],
],
],
'finished' => '\\Drupal\\taxonomy_delete\\TaxonomyDeleteBatch::finishProcess',
];
batch_set($batch);
}
}
}