diff --git a/config/services/drupal-console/taxonomy.yml b/config/services/drupal-console/taxonomy.yml new file mode 100644 index 000000000..c3b91acbc --- /dev/null +++ b/config/services/drupal-console/taxonomy.yml @@ -0,0 +1,5 @@ +services: + taxonomy_delete: + class: Drupal\Console\Command\Taxonomy\DeleteCommand + tags: + - { name: console.command } diff --git a/config/translations/en/taxonomy.term.delete.yml b/config/translations/en/taxonomy.term.delete.yml new file mode 100644 index 000000000..2135a5ac1 --- /dev/null +++ b/config/translations/en/taxonomy.term.delete.yml @@ -0,0 +1 @@ +description: 'Delete taxonomy terms from a vocabulary, command takes the VID as argument or all which will delete every term from every vocabulary' \ No newline at end of file diff --git a/src/Command/Taxonomy/DeleteTermCommand.php b/src/Command/Taxonomy/DeleteTermCommand.php new file mode 100644 index 000000000..6bce55aad --- /dev/null +++ b/src/Command/Taxonomy/DeleteTermCommand.php @@ -0,0 +1,44 @@ +setName('taxonomy:term:delete') + ->setDescription($this->trans('commands.taxonomy.term.delete.description')) + ->addArgument('vid',InputArgument::REQUIRED); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) { + + $io = new DrupalStyle($input, $output); + + $this->deleteExistingTerms($input->getArgument('vid'), $io); + + } + +} diff --git a/src/Command/Taxonomy/TermDeletionTrait.php b/src/Command/Taxonomy/TermDeletionTrait.php new file mode 100644 index 000000000..b9da5d347 --- /dev/null +++ b/src/Command/Taxonomy/TermDeletionTrait.php @@ -0,0 +1,55 @@ +get('entity.manager') + ->getStorage('taxonomy_term') + ->loadTree($selected_vocab->id()); + + foreach ($terms as $term) { + $treal = Term::load($term->tid); + if($treal !== null){ + $io->info("Deleting {$term->name} and all translations"); + $treal->delete(); + } + } + } + + } + +} \ No newline at end of file