From 727364375020a0fd373e9760985bbc892a079353 Mon Sep 17 00:00:00 2001 From: Miguel Date: Thu, 1 Feb 2018 01:27:38 -0600 Subject: [PATCH] [console] Add new option for generate ajax commmand. (#3755) --- src/Command/Generate/AjaxCommand.php | 18 ++++++++++++++++++ src/Generator/AjaxCommandGenerator.php | 3 ++- templates/module/module-libraries.yml.twig | 4 ++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Command/Generate/AjaxCommand.php b/src/Command/Generate/AjaxCommand.php index 7b2dc8fd1..b6d70b138 100644 --- a/src/Command/Generate/AjaxCommand.php +++ b/src/Command/Generate/AjaxCommand.php @@ -98,6 +98,12 @@ protected function configure() InputOption::VALUE_OPTIONAL, $this->trans('commands.generate.ajax.command.options.method') ) + ->addOption( + 'js-name', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.generate.ajax.command.options.js-name') + ) ->setAliases(['gac']); } @@ -114,12 +120,14 @@ protected function execute(InputInterface $input, OutputInterface $output) $module = $input->getOption('module'); $class = $this->validator->validateClassName($input->getOption('class')); $method = $input->getOption('method'); + $js_name = $input->getOption('js-name'); $this->generator->generate( [ 'module' => $module, 'class_name' => $class, 'method' => $method, + 'js_name' => $js_name, ] ); @@ -159,5 +167,15 @@ function ($class) { ); $input->setOption('method', $method); } + + // --js-name option + $js_name = $input->getOption('js-name'); + if (!$js_name) { + $js_name = $this->getIo()->ask( + $this->trans('commands.generate.ajax.command.questions.js-name'), + 'script' + ); + $input->setOption('js-name', $js_name); + } } } diff --git a/src/Generator/AjaxCommandGenerator.php b/src/Generator/AjaxCommandGenerator.php index 58137f771..fe5408d67 100644 --- a/src/Generator/AjaxCommandGenerator.php +++ b/src/Generator/AjaxCommandGenerator.php @@ -40,6 +40,7 @@ public function generate(array $parameters) { $class = $parameters['class_name']; $module = $parameters['module']; + $js_name = $parameters['js_name']; $moduleInstance = $this->extensionManager->getModule($module); $moduleDir = $moduleInstance->getPath(); @@ -51,7 +52,7 @@ public function generate(array $parameters) $this->renderFile( 'module/js/commands.php.twig', - $moduleDir . '/js/custom.js', + $moduleDir . '/js/' .$js_name. '.js', $parameters ); diff --git a/templates/module/module-libraries.yml.twig b/templates/module/module-libraries.yml.twig index 993058cfa..6a668a321 100644 --- a/templates/module/module-libraries.yml.twig +++ b/templates/module/module-libraries.yml.twig @@ -1,5 +1,5 @@ -{{ module }}.commands: +{{ module }}-library: js: - js/custom.js: {} + js/{{ js_name }}.js: {} dependencies: - core/drupal.ajax