Skip to content

Commit

Permalink
Add option to create config file on generate:form (#3218)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguel303 authored and jmolivas committed Mar 10, 2017
1 parent 580b60f commit 4cc52d2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
20 changes: 19 additions & 1 deletion src/Command/Generate/FormCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ protected function configure()
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
$this->trans('commands.common.options.services')
)
->addOption(
'config-file',
'',
InputOption::VALUE_NONE,
$this->trans('commands.generate.form.options.config-file')
)
->addOption(
'inputs',
'',
Expand Down Expand Up @@ -190,6 +196,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$module = $input->getOption('module');
$services = $input->getOption('services');
$path = $input->getOption('path');
$config_file = $input->getOption('config-file');
$class_name = $input->getOption('class');
$form_id = $input->getOption('form-id');
$form_type = $this->formType;
Expand All @@ -204,7 +211,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$this
->generator
->generate($module, $class_name, $form_id, $form_type, $build_services, $inputs, $path, $menu_link_gen, $menu_link_title, $menu_parent, $menu_link_desc);
->generate($module, $class_name, $form_id, $form_type, $build_services, $config_file, $inputs, $path,$menu_link_gen, $menu_link_title, $menu_parent, $menu_link_desc);

$this->chainQueue->addCommand('router:rebuild', []);
}
Expand Down Expand Up @@ -248,6 +255,17 @@ protected function interact(InputInterface $input, OutputInterface $output)
// @see use Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion
$services = $this->servicesQuestion($io);
$input->setOption('services', $services);

// --config_file option
$config_file = $input->getOption('config-file');

if (!$config_file) {
$config_file = $io->confirm(
$this->trans('commands.generate.form.questions.config-file'),
true
);
$input->setOption('config-file', $config_file);
}

// --inputs option
$inputs = $input->getOption('inputs');
Expand Down
19 changes: 12 additions & 7 deletions src/Generator/FormGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function __construct(
* @param $module
* @param $class_name
* @param $services
* @param $config_file
* @param $inputs
* @param $form_id
* @param $form_type
Expand All @@ -50,7 +51,7 @@ public function __construct(
* @param $menu_parent
* @param $menu_link_desc
*/
public function generate($module, $class_name, $form_id, $form_type, $services, $inputs, $path, $menu_link_gen, $menu_link_title, $menu_parent, $menu_link_desc)
public function generate($module, $class_name, $form_id, $form_type, $services, $config_file, $inputs, $path, $menu_link_gen, $menu_link_title, $menu_parent, $menu_link_desc)
{
$class_name_short = strtolower(
$this->stringConverter->removeSuffix($class_name)
Expand All @@ -59,6 +60,7 @@ public function generate($module, $class_name, $form_id, $form_type, $services,
$parameters = [
'class_name' => $class_name,
'services' => $services,
'config_file' => $config_file,
'inputs' => $inputs,
'module_name' => $module,
'form_id' => $form_id,
Expand Down Expand Up @@ -90,13 +92,16 @@ public function generate($module, $class_name, $form_id, $form_type, $services,
$this->extensionManager->getModule($module)->getFormPath() .'/'.$class_name.'.php',
$parameters
);

// Render defaults YML file.
if ($config_file == true) {
$this->renderFile(
'module/config/install/field.default.yml.twig',
$this->extensionManager->getModule($module)->getPath() .'/config/install/'.$module.'.'.$class_name_short.'.yml',
$parameters
);

// Render defaults YML file.
$this->renderFile(
'module/config/install/field.default.yml.twig',
$this->extensionManager->getModule($module)->getPath() .'/config/install/'.$module.'.'.$class_name_short.'.yml',
$parameters
);
}

if ($menu_link_gen == true) {
$this->renderFile(
Expand Down

0 comments on commit 4cc52d2

Please sign in to comment.