X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FCreate%2FNodesCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FCreate%2FNodesCommand.php;h=3e8e6f929f6930a80cdde9f3b5422b3935ff3b17;hp=36f3d98a48fdb72e5137114dd1218a3850820d10;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/vendor/drupal/console/src/Command/Create/NodesCommand.php b/vendor/drupal/console/src/Command/Create/NodesCommand.php index 36f3d98a4..3e8e6f929 100644 --- a/vendor/drupal/console/src/Command/Create/NodesCommand.php +++ b/vendor/drupal/console/src/Command/Create/NodesCommand.php @@ -11,13 +11,11 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Command\Command; +use Drupal\Console\Core\Command\Command; use Drupal\Console\Annotations\DrupalCommand; -use Drupal\Console\Core\Command\Shared\CommandTrait; use Drupal\Console\Command\Shared\CreateTrait; use Drupal\Console\Utils\Create\NodeData; use Drupal\Console\Utils\DrupalApi; -use Drupal\Console\Core\Style\DrupalStyle; use Drupal\Core\Language\LanguageInterface; /** @@ -33,7 +31,6 @@ use Drupal\Core\Language\LanguageInterface; class NodesCommand extends Command { use CreateTrait; - use CommandTrait; /** * @var DrupalApi @@ -95,7 +92,7 @@ class NodesCommand extends Command null, InputOption::VALUE_OPTIONAL, $this->trans('commands.create.nodes.options.language') - ); + )->setAliases(['crn']); } /** @@ -103,12 +100,10 @@ class NodesCommand extends Command */ protected function interact(InputInterface $input, OutputInterface $output) { - $io = new DrupalStyle($input, $output); - $contentTypes = $input->getArgument('content-types'); if (!$contentTypes) { $bundles = $this->drupalApi->getBundles(); - $contentTypes = $io->choice( + $contentTypes = $this->getIo()->choice( $this->trans('commands.create.nodes.questions.content-type'), array_values($bundles), null, @@ -127,7 +122,7 @@ class NodesCommand extends Command $limit = $input->getOption('limit'); if (!$limit) { - $limit = $io->ask( + $limit = $this->getIo()->ask( $this->trans('commands.create.nodes.questions.limit'), 25 ); @@ -136,7 +131,7 @@ class NodesCommand extends Command $titleWords = $input->getOption('title-words'); if (!$titleWords) { - $titleWords = $io->ask( + $titleWords = $this->getIo()->ask( $this->trans('commands.create.nodes.questions.title-words'), 5 ); @@ -148,7 +143,7 @@ class NodesCommand extends Command if (!$timeRange) { $timeRanges = $this->getTimeRange(); - $timeRange = $io->choice( + $timeRange = $this->getIo()->choice( $this->trans('commands.create.nodes.questions.time-range'), array_values($timeRanges) ); @@ -174,7 +169,7 @@ class NodesCommand extends Command $language = $input->getOption('language'); // If no language option or invalid language code in option. if (!$language || !array_key_exists($language, $language_list)) { - $language = $io->choice( + $language = $this->getIo()->choice( $this->trans('commands.create.nodes.questions.language'), $language_list ); @@ -191,8 +186,6 @@ class NodesCommand extends Command */ protected function execute(InputInterface $input, OutputInterface $output) { - $io = new DrupalStyle($input, $output); - $contentTypes = $input->getArgument('content-types'); $limit = $input->getOption('limit')?:25; $titleWords = $input->getOption('title-words')?:5; @@ -210,31 +203,42 @@ class NodesCommand extends Command $contentTypes = $available_types; } - $nodes = $this->createNodeData->create( + $result = $this->createNodeData->create( $contentTypes, $limit, $titleWords, $timeRange, $language ); - - $nodes = is_array($nodes) ? $nodes : [$nodes]; - - $tableHeader = [ - $this->trans('commands.create.nodes.messages.node-id'), - $this->trans('commands.create.nodes.messages.content-type'), - $this->trans('commands.create.nodes.messages.title'), - $this->trans('commands.create.nodes.messages.created'), - ]; - - $io->table($tableHeader, $nodes['success']); - - $io->success( - sprintf( - $this->trans('commands.create.nodes.messages.created-nodes'), - $limit - ) - ); + + if ($result['success']) { + $tableHeader = [ + $this->trans('commands.create.nodes.messages.node-id'), + $this->trans('commands.create.nodes.messages.content-type'), + $this->trans('commands.create.nodes.messages.title'), + $this->trans('commands.create.nodes.messages.created'), + ]; + + $this->getIo()->table($tableHeader, $result['success']); + + $this->getIo()->success( + sprintf( + $this->trans('commands.create.nodes.messages.created-nodes'), + count($result['success']) + ) + ); + } + + if (isset($result['error'])) { + foreach ($result['error'] as $error) { + $this->getIo()->error( + sprintf( + $this->trans('commands.create.nodes.messages.error'), + $error + ) + ); + } + } return 0; }