namespace Drupal\Console\Command\Generate;
+use Drupal\Console\Utils\Validator;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Console\Command\Command;
+use Drupal\Console\Core\Command\Command;
use Drupal\Core\Entity\EntityTypeRepository;
-use Drupal\Console\Core\Command\Shared\CommandTrait;
use Drupal\Console\Generator\PluginConditionGenerator;
use Drupal\Console\Command\Shared\ModuleTrait;
use Drupal\Console\Command\Shared\ConfirmationTrait;
-use Drupal\Console\Core\Style\DrupalStyle;
use Drupal\Console\Extension\Manager;
use Drupal\Console\Core\Utils\ChainQueue;
use Drupal\Console\Core\Utils\StringConverter;
*/
class PluginConditionCommand extends Command
{
- use CommandTrait;
use ModuleTrait;
use ConfirmationTrait;
*/
protected $stringConverter;
+ /**
+ * @var Validator
+ */
+ protected $validator;
+
/**
* PluginConditionCommand constructor.
* @param ChainQueue $chainQueue
* @param EntityTypeRepository $entitytyperepository
* @param StringConverter $stringConverter
+ * @param Validator $validator
*/
public function __construct(
Manager $extensionManager,
PluginConditionGenerator $generator,
ChainQueue $chainQueue,
EntityTypeRepository $entitytyperepository,
- StringConverter $stringConverter
+ StringConverter $stringConverter,
+ Validator $validator
) {
$this->extensionManager = $extensionManager;
$this->generator = $generator;
$this->chainQueue = $chainQueue;
$this->entitytyperepository = $entitytyperepository;
$this->stringConverter = $stringConverter;
+ $this->validator = $validator;
parent::__construct();
}
->setName('generate:plugin:condition')
->setDescription($this->trans('commands.generate.plugin.condition.description'))
->setHelp($this->trans('commands.generate.plugin.condition.help'))
- ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module'))
+ ->addOption(
+ 'module',
+ null,
+ InputOption::VALUE_REQUIRED,
+ $this->trans('commands.common.options.module')
+ )
->addOption(
'class',
null,
null,
InputOption::VALUE_OPTIONAL,
$this->trans('commands.generate.plugin.condition.options.context-definition-required')
- );
+ )
+ ->setAliases(['gpco']);
}
/**
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
- $io = new DrupalStyle($input, $output);
-
- // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
- if (!$this->confirmGeneration($io)) {
+ // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmOperation
+ if (!$this->confirmOperation()) {
return 1;
}
$module = $input->getOption('module');
- $class_name = $input->getOption('class');
+ $class_name = $this->validator->validateClassName($input->getOption('class'));
$label = $input->getOption('label');
$plugin_id = $input->getOption('plugin-id');
$context_definition_id = $input->getOption('context-definition-id');
$context_definition_label = $input->getOption('context-definition-label');
$context_definition_required = $input->getOption('context-definition-required')?'TRUE':'FALSE';
- $this
- ->generator
- ->generate($module, $class_name, $label, $plugin_id, $context_definition_id, $context_definition_label, $context_definition_required);
+ $this->generator->generate([
+ 'module' => $module,
+ 'class_name' => $class_name,
+ 'label' => $label,
+ 'plugin_id' => $plugin_id,
+ 'context_definition_id' => $context_definition_id,
+ 'context_definition_label' => $context_definition_label,
+ 'context_definition_required' => $context_definition_required,
+ ]);
$this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']);
protected function interact(InputInterface $input, OutputInterface $output)
{
- $io = new DrupalStyle($input, $output);
-
$entityTypeRepository = $this->entitytyperepository;
$entity_types = $entityTypeRepository->getEntityTypeLabels(true);
// --module option
- $module = $input->getOption('module');
- if (!$module) {
- // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
- $module = $this->moduleQuestion($io);
- }
- $input->setOption('module', $module);
+ $this->getModuleOption();
// --class option
$class = $input->getOption('class');
if (!$class) {
- $class = $io->ask(
+ $class = $this->getIo()->ask(
$this->trans('commands.generate.plugin.condition.questions.class'),
- 'ExampleCondition'
+ 'ExampleCondition',
+ function ($class) {
+ return $this->validator->validateClassName($class);
+ }
);
$input->setOption('class', $class);
}
// --plugin label option
$label = $input->getOption('label');
if (!$label) {
- $label = $io->ask(
+ $label = $this->getIo()->ask(
$this->trans('commands.generate.plugin.condition.questions.label'),
$this->stringConverter->camelCaseToHuman($class)
);
// --plugin-id option
$pluginId = $input->getOption('plugin-id');
if (!$pluginId) {
- $pluginId = $io->ask(
+ $pluginId = $this->getIo()->ask(
$this->trans('commands.generate.plugin.condition.questions.plugin-id'),
$this->stringConverter->camelCaseToUnderscore($class)
);
$context_definition_id = $input->getOption('context-definition-id');
if (!$context_definition_id) {
$context_type = ['language' => 'Language', "entity" => "Entity"];
- $context_type_sel = $io->choice(
+ $context_type_sel = $this->getIo()->choice(
$this->trans('commands.generate.plugin.condition.questions.context-type'),
array_values($context_type)
);
$context_definition_id = $context_type_sel;
$context_definition_id_value = ucfirst($context_type_sel);
} else {
- $content_entity_types_sel = $io->choice(
+ $content_entity_types_sel = $this->getIo()->choice(
$this->trans('commands.generate.plugin.condition.questions.context-entity-type'),
array_keys($entity_types)
);
$contextDefinitionIdList = $entity_types[$content_entity_types_sel];
- $context_definition_id_sel = $io->choice(
+ $context_definition_id_sel = $this->getIo()->choice(
$this->trans('commands.generate.plugin.condition.questions.context-definition-id'),
array_values($contextDefinitionIdList)
);
$context_definition_label = $input->getOption('context-definition-label');
if (!$context_definition_label) {
- $context_definition_label = $io->ask(
+ $context_definition_label = $this->getIo()->ask(
$this->trans('commands.generate.plugin.condition.questions.context-definition-label'),
$context_definition_id_value?:null
);
$context_definition_required = $input->getOption('context-definition-required');
if (empty($context_definition_required)) {
- $context_definition_required = $io->confirm(
+ $context_definition_required = $this->getIo()->confirm(
$this->trans('commands.generate.plugin.condition.questions.context-definition-required'),
true
);