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;
/**
class NodesCommand extends Command
{
use CreateTrait;
- use CommandTrait;
/**
* @var DrupalApi
null,
InputOption::VALUE_OPTIONAL,
$this->trans('commands.create.nodes.options.language')
- );
+ )->setAliases(['crn']);
}
/**
*/
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,
$limit = $input->getOption('limit');
if (!$limit) {
- $limit = $io->ask(
+ $limit = $this->getIo()->ask(
$this->trans('commands.create.nodes.questions.limit'),
25
);
$titleWords = $input->getOption('title-words');
if (!$titleWords) {
- $titleWords = $io->ask(
+ $titleWords = $this->getIo()->ask(
$this->trans('commands.create.nodes.questions.title-words'),
5
);
if (!$timeRange) {
$timeRanges = $this->getTimeRange();
- $timeRange = $io->choice(
+ $timeRange = $this->getIo()->choice(
$this->trans('commands.create.nodes.questions.time-range'),
array_values($timeRanges)
);
$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
);
*/
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;
$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;
}