4 * Contains \Drupal\Console\Command\Create\CommentsCommand.
7 namespace Drupal\Console\Command\Create;
9 use Symfony\Component\Console\Input\InputOption;
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Output\OutputInterface;
12 use Symfony\Component\Console\Command\Command;
13 use Drupal\Console\Core\Command\Shared\CommandTrait;
14 use Drupal\Console\Command\Shared\CreateTrait;
15 use Drupal\Console\Utils\Create\CommentData;
16 use Drupal\Console\Core\Style\DrupalStyle;
19 * Class CommentsCommand
21 * @package Drupal\Console\Command\Generate
23 class CommentsCommand extends Command
31 protected $createCommentData;
34 * CommentsCommand constructor.
36 * @param CommentData $createCommentData
38 public function __construct(CommentData $createCommentData)
40 $this->createCommentData = $createCommentData;
41 parent::__construct();
47 protected function configure()
50 ->setName('create:comments')
51 ->setDescription($this->trans('commands.create.comments.description'))
54 InputOption::VALUE_REQUIRED,
55 $this->trans('commands.create.comments.arguments.node-id'),
61 InputOption::VALUE_OPTIONAL,
62 $this->trans('commands.create.comments.options.limit')
67 InputOption::VALUE_OPTIONAL,
68 $this->trans('commands.create.comments.options.title-words')
73 InputOption::VALUE_OPTIONAL,
74 $this->trans('commands.create.comments.options.time-range')
81 protected function interact(InputInterface $input, OutputInterface $output)
83 $io = new DrupalStyle($input, $output);
85 $nodeId = $input->getArgument('node-id');
88 $this->trans('commands.create.comments.questions.node-id')
90 $input->setArgument('node-id', $nodeId);
93 $limit = $input->getOption('limit');
96 $this->trans('commands.create.comments.questions.limit'),
99 $input->setOption('limit', $limit);
102 $titleWords = $input->getOption('title-words');
104 $titleWords = $io->ask(
105 $this->trans('commands.create.comments.questions.title-words'),
109 $input->setOption('title-words', $titleWords);
112 $timeRange = $input->getOption('time-range');
114 $timeRanges = $this->getTimeRange();
116 $timeRange = $io->choice(
117 $this->trans('commands.create.comments.questions.time-range'),
118 array_values($timeRanges)
121 $input->setOption('time-range', array_search($timeRange, $timeRanges));
128 protected function execute(InputInterface $input, OutputInterface $output)
130 $io = new DrupalStyle($input, $output);
132 $nodeId = $input->getArgument('node-id')?:1;
133 $limit = $input->getOption('limit')?:25;
134 $titleWords = $input->getOption('title-words')?:5;
135 $timeRange = $input->getOption('time-range')?:31536000;
137 $comments = $this->createCommentData->create(
145 $this->trans('commands.create.comments.messages.node-id'),
146 $this->trans('commands.create.comments.messages.comment-id'),
147 $this->trans('commands.create.comments.messages.title'),
148 $this->trans('commands.create.comments.messages.created'),
151 $io->table($tableHeader, $comments['success']);
155 $this->trans('commands.create.comments.messages.created-comments'),