5 * Contains \Drupal\Console\Command\Create\TermsCommand.
8 namespace Drupal\Console\Command\Create;
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputOption;
12 use Symfony\Component\Console\Input\InputInterface;
13 use Symfony\Component\Console\Output\OutputInterface;
14 use Symfony\Component\Console\Command\Command;
15 use Drupal\Console\Core\Command\Shared\CommandTrait;
16 use Drupal\Console\Annotations\DrupalCommand;
17 use Drupal\Console\Utils\Create\TermData;
18 use Drupal\Console\Utils\DrupalApi;
19 use Drupal\Console\Core\Style\DrupalStyle;
24 * @package Drupal\Console\Command\Generate
27 * extension = "features",
28 * extensionType = "module",
29 * dependencies={"taxonomy"}
32 class TermsCommand extends Command
43 protected $createTermData;
46 * TermsCommand constructor.
48 * @param DrupalApi $drupalApi
49 * @param TermData $createTermData
51 public function __construct(
53 TermData $createTermData
55 $this->drupalApi = $drupalApi;
56 $this->createTermData = $createTermData;
57 parent::__construct();
63 protected function configure()
66 ->setName('create:terms')
67 ->setDescription($this->trans('commands.create.terms.description'))
70 InputArgument::IS_ARRAY,
71 $this->trans('commands.create.terms.arguments.vocabularies')
76 InputOption::VALUE_OPTIONAL,
77 $this->trans('commands.create.terms.options.limit')
82 InputOption::VALUE_OPTIONAL,
83 $this->trans('commands.create.terms.options.name-words')
90 protected function interact(InputInterface $input, OutputInterface $output)
92 $io = new DrupalStyle($input, $output);
94 $vocabularies = $input->getArgument('vocabularies');
96 $vocabularies = $this->drupalApi->getVocabularies();
98 $this->trans('commands.create.terms.questions.vocabularies'),
99 array_values($vocabularies),
105 function ($vid) use ($vocabularies) {
106 return array_search($vid, $vocabularies);
111 $input->setArgument('vocabularies', $vids);
114 $limit = $input->getOption('limit');
117 $this->trans('commands.create.terms.questions.limit'),
120 $input->setOption('limit', $limit);
123 $nameWords = $input->getOption('name-words');
125 $nameWords = $io->ask(
126 $this->trans('commands.create.terms.questions.name-words'),
130 $input->setOption('name-words', $nameWords);
137 protected function execute(InputInterface $input, OutputInterface $output)
139 $io = new DrupalStyle($input, $output);
141 $vocabularies = $input->getArgument('vocabularies');
142 $limit = $input->getOption('limit')?:25;
143 $nameWords = $input->getOption('name-words')?:5;
145 if (!$vocabularies) {
146 $vocabularies = array_keys($this->drupalApi->getVocabularies());
149 $terms = $this->createTermData->create(
156 $this->trans('commands.create.terms.messages.term-id'),
157 $this->trans('commands.create.terms.messages.vocabulary'),
158 $this->trans('commands.create.terms.messages.name'),
161 $io->table($tableHeader, $terms['success']);
165 $this->trans('commands.create.terms.messages.created-terms'),