X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FGenerate%2FPluginFieldFormatterCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FGenerate%2FPluginFieldFormatterCommand.php;h=4c07a4c16e3a7b3f6e923760669f917fdffef18c;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=e930070ef3f8fc098511cee6c3c8c9279417405b;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website diff --git a/vendor/drupal/console/src/Command/Generate/PluginFieldFormatterCommand.php b/vendor/drupal/console/src/Command/Generate/PluginFieldFormatterCommand.php index e930070ef..4c07a4c16 100644 --- a/vendor/drupal/console/src/Command/Generate/PluginFieldFormatterCommand.php +++ b/vendor/drupal/console/src/Command/Generate/PluginFieldFormatterCommand.php @@ -7,17 +7,16 @@ 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 Drupal\Console\Generator\PluginFieldFormatterGenerator; use Drupal\Console\Command\Shared\ModuleTrait; use Drupal\Console\Command\Shared\ConfirmationTrait; -use Symfony\Component\Console\Command\Command; -use Drupal\Console\Core\Style\DrupalStyle; +use Drupal\Console\Core\Command\Command; use Drupal\Core\Field\FieldTypePluginManager; use Drupal\Console\Extension\Manager; -use Drupal\Console\Core\Command\Shared\CommandTrait; use Drupal\Console\Core\Utils\StringConverter; use Drupal\Console\Core\Utils\ChainQueue; @@ -30,7 +29,6 @@ class PluginFieldFormatterCommand extends Command { use ModuleTrait; use ConfirmationTrait; - use CommandTrait; /** * @var Manager @@ -47,6 +45,11 @@ class PluginFieldFormatterCommand extends Command */ protected $stringConverter; + /** + * @var Validator + */ + protected $validator; + /** * @var FieldTypePluginManager */ @@ -64,6 +67,7 @@ class PluginFieldFormatterCommand extends Command * @param Manager $extensionManager * @param PluginFieldFormatterGenerator $generator * @param StringConverter $stringConverter + * @param Validator $validator * @param FieldTypePluginManager $fieldTypePluginManager * @param ChainQueue $chainQueue */ @@ -71,12 +75,14 @@ class PluginFieldFormatterCommand extends Command Manager $extensionManager, PluginFieldFormatterGenerator $generator, StringConverter $stringConverter, + Validator $validator, FieldTypePluginManager $fieldTypePluginManager, ChainQueue $chainQueue ) { $this->extensionManager = $extensionManager; $this->generator = $generator; $this->stringConverter = $stringConverter; + $this->validator = $validator; $this->fieldTypePluginManager = $fieldTypePluginManager; $this->chainQueue = $chainQueue; parent::__construct(); @@ -88,7 +94,12 @@ class PluginFieldFormatterCommand extends Command ->setName('generate:plugin:fieldformatter') ->setDescription($this->trans('commands.generate.plugin.fieldformatter.description')) ->setHelp($this->trans('commands.generate.plugin.fieldformatter.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, @@ -112,7 +123,8 @@ class PluginFieldFormatterCommand extends Command null, InputOption::VALUE_OPTIONAL, $this->trans('commands.generate.plugin.fieldformatter.options.field-type') - ); + ) + ->setAliases(['gpff']); } /** @@ -120,20 +132,24 @@ class PluginFieldFormatterCommand extends Command */ 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'); $field_type = $input->getOption('field-type'); - $this->generator->generate($module, $class_name, $label, $plugin_id, $field_type); + $this->generator->generate([ + 'module' => $module, + 'class_name' => $class_name, + 'label' => $label, + 'plugin_id' => $plugin_id, + 'field_type' => $field_type, + ]); $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); @@ -142,22 +158,18 @@ class PluginFieldFormatterCommand extends Command protected function interact(InputInterface $input, OutputInterface $output) { - $io = new DrupalStyle($input, $output); - // --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.fieldformatter.questions.class'), - 'ExampleFieldFormatter' + 'ExampleFieldFormatter', + function ($class) { + return $this->validator->validateClassName($class); + } ); $input->setOption('class', $class); } @@ -165,7 +177,7 @@ class PluginFieldFormatterCommand extends Command // --plugin label option $label = $input->getOption('label'); if (!$label) { - $label = $io->ask( + $label = $this->getIo()->ask( $this->trans('commands.generate.plugin.fieldformatter.questions.label'), $this->stringConverter->camelCaseToHuman($class) ); @@ -175,7 +187,7 @@ class PluginFieldFormatterCommand extends Command // --name option $plugin_id = $input->getOption('plugin-id'); if (!$plugin_id) { - $plugin_id = $io->ask( + $plugin_id = $this->getIo()->ask( $this->trans('commands.generate.plugin.fieldformatter.questions.plugin-id'), $this->stringConverter->camelCaseToUnderscore($class) ); @@ -193,7 +205,7 @@ class PluginFieldFormatterCommand extends Command } } - $field_type = $io->choice( + $field_type = $this->getIo()->choice( $this->trans('commands.generate.plugin.fieldwidget.questions.field-type'), $field_type_options );