X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FCreate%2FTermsCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FCreate%2FTermsCommand.php;h=0822c4a749f795debba213f0491a9f7002dc3e36;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/vendor/drupal/console/src/Command/Create/TermsCommand.php b/vendor/drupal/console/src/Command/Create/TermsCommand.php new file mode 100644 index 000000000..0822c4a74 --- /dev/null +++ b/vendor/drupal/console/src/Command/Create/TermsCommand.php @@ -0,0 +1,172 @@ +drupalApi = $drupalApi; + $this->createTermData = $createTermData; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('create:terms') + ->setDescription($this->trans('commands.create.terms.description')) + ->addArgument( + 'vocabularies', + InputArgument::IS_ARRAY, + $this->trans('commands.create.terms.arguments.vocabularies') + ) + ->addOption( + 'limit', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.create.terms.options.limit') + ) + ->addOption( + 'name-words', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.create.terms.options.name-words') + ); + } + + /** + * {@inheritdoc} + */ + protected function interact(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $vocabularies = $input->getArgument('vocabularies'); + if (!$vocabularies) { + $vocabularies = $this->drupalApi->getVocabularies(); + $vids = $io->choice( + $this->trans('commands.create.terms.questions.vocabularies'), + array_values($vocabularies), + null, + true + ); + + $vids = array_map( + function ($vid) use ($vocabularies) { + return array_search($vid, $vocabularies); + }, + $vids + ); + + $input->setArgument('vocabularies', $vids); + } + + $limit = $input->getOption('limit'); + if (!$limit) { + $limit = $io->ask( + $this->trans('commands.create.terms.questions.limit'), + 25 + ); + $input->setOption('limit', $limit); + } + + $nameWords = $input->getOption('name-words'); + if (!$nameWords) { + $nameWords = $io->ask( + $this->trans('commands.create.terms.questions.name-words'), + 5 + ); + + $input->setOption('name-words', $nameWords); + } + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $vocabularies = $input->getArgument('vocabularies'); + $limit = $input->getOption('limit')?:25; + $nameWords = $input->getOption('name-words')?:5; + + if (!$vocabularies) { + $vocabularies = array_keys($this->drupalApi->getVocabularies()); + } + + $terms = $this->createTermData->create( + $vocabularies, + $limit, + $nameWords + ); + + $tableHeader = [ + $this->trans('commands.create.terms.messages.term-id'), + $this->trans('commands.create.terms.messages.vocabulary'), + $this->trans('commands.create.terms.messages.name'), + ]; + + $io->table($tableHeader, $terms['success']); + + $io->success( + sprintf( + $this->trans('commands.create.terms.messages.created-terms'), + $limit + ) + ); + + return 0; + } +}