X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FGenerate%2FModuleCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FGenerate%2FModuleCommand.php;h=23a8ccb5dafab83b9639789acdb44d5b26ea6913;hp=0330fb564137d5eb07df744131dd1ed422ec88d5;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/vendor/drupal/console/src/Command/Generate/ModuleCommand.php b/vendor/drupal/console/src/Command/Generate/ModuleCommand.php index 0330fb564..23a8ccb5d 100644 --- a/vendor/drupal/console/src/Command/Generate/ModuleCommand.php +++ b/vendor/drupal/console/src/Command/Generate/ModuleCommand.php @@ -7,23 +7,20 @@ namespace Drupal\Console\Command\Generate; -use Symfony\Component\Config\Definition\Exception\Exception; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Drupal\Console\Generator\ModuleGenerator; 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\Console\Utils\Validator; -use Drupal\Console\Core\Command\Shared\CommandTrait; use Drupal\Console\Core\Utils\StringConverter; use Drupal\Console\Utils\DrupalApi; +use Webmozart\PathUtil\Path; class ModuleCommand extends Command { use ConfirmationTrait; - use CommandTrait; /** * @var ModuleGenerator @@ -164,7 +161,8 @@ class ModuleCommand extends Command null, InputOption::VALUE_OPTIONAL, $this->trans('commands.generate.module.options.twigtemplate') - ); + ) + ->setAliases(['gm']); } /** @@ -172,17 +170,18 @@ class ModuleCommand extends Command */ protected function execute(InputInterface $input, OutputInterface $output) { - $io = new DrupalStyle($input, $output); - $yes = $input->hasOption('yes')?$input->getOption('yes'):false; - - // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration - if (!$this->confirmGeneration($io, $yes)) { + // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmOperation + if (!$this->confirmOperation()) { return 1; } $module = $this->validator->validateModuleName($input->getOption('module')); - $modulePath = $this->appRoot . $input->getOption('module-path'); + // Get the profile path and define a profile path if it is null + // Check that it is an absolute path or otherwise create an absolute path using appRoot + $modulePath = $input->getOption('module-path'); + $modulePath = $modulePath == null ? 'modules/custom' : $modulePath; + $modulePath = Path::isAbsolute($modulePath) ? $modulePath : Path::makeAbsolute($modulePath, $this->appRoot); $modulePath = $this->validator->validateModulePath($modulePath, true); $machineName = $this->validator->validateMachineName($input->getOption('machine-name')); @@ -195,25 +194,25 @@ class ModuleCommand extends Command $dependencies = $this->validator->validateExtensions( $input->getOption('dependencies'), 'module', - $io + $this->getIo() ); $test = $input->getOption('test'); $twigTemplate = $input->getOption('twigtemplate'); - $this->generator->generate( - $module, - $machineName, - $modulePath, - $description, - $core, - $package, - $moduleFile, - $featuresBundle, - $composer, - $dependencies, - $test, - $twigTemplate - ); + $this->generator->generate([ + 'module' => $module, + 'machine_name' => $machineName, + 'module_path' => $modulePath, + 'description' => $description, + 'core' => $core, + 'package' => $package, + 'module_file' => $moduleFile, + 'features_bundle' => $featuresBundle, + 'composer' => $composer, + 'dependencies' => $dependencies, + 'test' => $test, + 'twig_template' => $twigTemplate, + ]); return 0; } @@ -223,8 +222,6 @@ class ModuleCommand extends Command */ protected function interact(InputInterface $input, OutputInterface $output) { - $io = new DrupalStyle($input, $output); - $validator = $this->validator; try { @@ -233,13 +230,13 @@ class ModuleCommand extends Command $input->getOption('module') ) : null; } catch (\Exception $error) { - $io->error($error->getMessage()); + $this->getIo()->error($error->getMessage()); return 1; } if (!$module) { - $module = $io->ask( + $module = $this->getIo()->ask( $this->trans('commands.generate.module.questions.module'), null, function ($module) use ($validator) { @@ -255,11 +252,11 @@ class ModuleCommand extends Command $input->getOption('machine-name') ) : null; } catch (\Exception $error) { - $io->error($error->getMessage()); + $this->getIo()->error($error->getMessage()); } if (!$machineName) { - $machineName = $io->ask( + $machineName = $this->getIo()->ask( $this->trans('commands.generate.module.questions.machine-name'), $this->stringConverter->createMachineName($module), function ($machine_name) use ($validator) { @@ -271,13 +268,12 @@ class ModuleCommand extends Command $modulePath = $input->getOption('module-path'); if (!$modulePath) { - $drupalRoot = $this->appRoot; - $modulePath = $io->ask( + $modulePath = $this->getIo()->ask( $this->trans('commands.generate.module.questions.module-path'), - '/modules/custom', - function ($modulePath) use ($drupalRoot, $machineName) { - $modulePath = ($modulePath[0] != '/' ? '/' : '').$modulePath; - $fullPath = $drupalRoot.$modulePath.'/'.$machineName; + 'modules/custom', + function ($modulePath) use ($machineName) { + $fullPath = Path::isAbsolute($modulePath) ? $modulePath : Path::makeAbsolute($modulePath, $this->appRoot); + $fullPath = $fullPath.'/'.$machineName; if (file_exists($fullPath)) { throw new \InvalidArgumentException( sprintf( @@ -295,16 +291,16 @@ class ModuleCommand extends Command $description = $input->getOption('description'); if (!$description) { - $description = $io->ask( + $description = $this->getIo()->ask( $this->trans('commands.generate.module.questions.description'), - 'My Awesome Module' + $this->trans('commands.generate.module.suggestions.my-awesome-module') ); } $input->setOption('description', $description); $package = $input->getOption('package'); if (!$package) { - $package = $io->ask( + $package = $this->getIo()->ask( $this->trans('commands.generate.module.questions.package'), 'Custom' ); @@ -313,7 +309,7 @@ class ModuleCommand extends Command $core = $input->getOption('core'); if (!$core) { - $core = $io->ask( + $core = $this->getIo()->ask( $this->trans('commands.generate.module.questions.core'), '8.x', function ($core) { // Only allow 8.x and higher as core version. @@ -334,7 +330,7 @@ class ModuleCommand extends Command $moduleFile = $input->getOption('module-file'); if (!$moduleFile) { - $moduleFile = $io->confirm( + $moduleFile = $this->getIo()->confirm( $this->trans('commands.generate.module.questions.module-file'), true ); @@ -343,12 +339,12 @@ class ModuleCommand extends Command $featuresBundle = $input->getOption('features-bundle'); if (!$featuresBundle) { - $featuresSupport = $io->confirm( + $featuresSupport = $this->getIo()->confirm( $this->trans('commands.generate.module.questions.features-support'), false ); if ($featuresSupport) { - $featuresBundle = $io->ask( + $featuresBundle = $this->getIo()->ask( $this->trans('commands.generate.module.questions.features-bundle'), 'default' ); @@ -358,7 +354,7 @@ class ModuleCommand extends Command $composer = $input->getOption('composer'); if (!$composer) { - $composer = $io->confirm( + $composer = $this->getIo()->confirm( $this->trans('commands.generate.module.questions.composer'), true ); @@ -367,12 +363,12 @@ class ModuleCommand extends Command $dependencies = $input->getOption('dependencies'); if (!$dependencies) { - $addDependencies = $io->confirm( + $addDependencies = $this->getIo()->confirm( $this->trans('commands.generate.module.questions.dependencies'), false ); if ($addDependencies) { - $dependencies = $io->ask( + $dependencies = $this->getIo()->ask( $this->trans('commands.generate.module.options.dependencies') ); } @@ -381,7 +377,7 @@ class ModuleCommand extends Command $test = $input->getOption('test'); if (!$test) { - $test = $io->confirm( + $test = $this->getIo()->confirm( $this->trans('commands.generate.module.questions.test'), true ); @@ -390,19 +386,11 @@ class ModuleCommand extends Command $twigtemplate = $input->getOption('twigtemplate'); if (!$twigtemplate) { - $twigtemplate = $io->confirm( + $twigtemplate = $this->getIo()->confirm( $this->trans('commands.generate.module.questions.twigtemplate'), true ); $input->setOption('twigtemplate', $twigtemplate); } } - - /** - * @return ModuleGenerator - */ - protected function createGenerator() - { - return new ModuleGenerator(); - } }