Пример #1
0
 /**
  * @param  $module
  * @param  $class_name
  * @param  $services
  * @param  $inputs
  * @param  $form_id
  * @param  $form_type
  * @param  $path
  * @param  $menu_link_gen
  * @param  $menu_link_title
  * @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)
 {
     $class_name_short = strtolower($this->stringConverter->removeSuffix($class_name));
     $parameters = array('class_name' => $class_name, 'services' => $services, 'inputs' => $inputs, 'module_name' => $module, 'form_id' => $form_id, 'path' => $path, 'route_name' => $class_name, 'menu_link_title' => $menu_link_title, 'menu_parent' => $menu_parent, 'menu_link_desc' => $menu_link_desc, 'class_name_short' => $class_name_short);
     if ($form_type == 'ConfigFormBase') {
         $template = 'module/src/Form/form-config.php.twig';
         $parameters['config_form'] = true;
     } else {
         $template = 'module/src/Form/form.php.twig';
         $parameters['config_form'] = false;
     }
     $this->renderFile('module/routing-form.yml.twig', $this->extensionManager->getModule($module)->getPath() . '/' . $module . '.routing.yml', $parameters, FILE_APPEND);
     $this->renderFile($template, $this->extensionManager->getModule($module)->getFormPath() . '/' . $class_name . '.php', $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('module/links.menu.yml.twig', $this->extensionManager->getModule($module)->getPath() . '/' . $module . '.links.menu.yml', $parameters, FILE_APPEND);
     }
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 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);
     }
     // --class option
     $className = $input->getOption('class');
     if (!$className) {
         $className = $io->ask($this->trans('commands.generate.form.questions.class'), 'DefaultForm');
         $input->setOption('class', $className);
     }
     // --form-id option
     $formId = $input->getOption('form-id');
     if (!$formId) {
         $formId = $io->ask($this->trans('commands.generate.form.questions.form-id'), $this->stringConverter->camelCaseToMachineName($className));
         $input->setOption('form-id', $formId);
     }
     // --services option
     // @see use Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion
     $services = $this->servicesQuestion($io);
     $input->setOption('services', $services);
     // --inputs option
     $inputs = $input->getOption('inputs');
     if (!$inputs) {
         // @see \Drupal\Console\Command\Shared\FormTrait::formQuestion
         $inputs = $this->formQuestion($io);
         $input->setOption('inputs', $inputs);
     }
     $path = $input->getOption('path');
     if (!$path) {
         if ($this->formType == 'ConfigFormBase') {
             $form_path = '/admin/config/{{ module_name }}/{{ class_name_short }}';
             $form_path = sprintf('/admin/config/%s/%s', $module, strtolower($this->stringConverter->removeSuffix($className)));
         } else {
             $form_path = sprintf('/%s/form/%s', $module, $this->stringConverter->camelCaseToMachineName($this->stringConverter->removeSuffix($className)));
         }
         $path = $io->ask($this->trans('commands.generate.form.questions.path'), $form_path, function ($path) {
             if (count($this->routeProvider->getRoutesByPattern($path)) > 0) {
                 throw new \InvalidArgumentException(sprintf($this->trans('commands.generate.form.messages.path-already-added'), $path));
             }
             return $path;
         });
         $input->setOption('path', $path);
     }
     // --link option for links.menu
     if ($this->formType == 'ConfigFormBase') {
         $menu_options = $this->menuQuestion($io, $className);
         $menu_link_gen = $input->getOption('menu_link_gen');
         $menu_link_title = $input->getOption('menu_link_title');
         $menu_parent = $input->getOption('menu_parent');
         $menu_link_desc = $input->getOption('menu_link_desc');
         if (!$menu_link_gen || !$menu_link_title || !$menu_parent || !$menu_link_desc) {
             $input->setOption('menu_link_gen', $menu_options['menu_link_gen']);
             $input->setOption('menu_link_title', $menu_options['menu_link_title']);
             $input->setOption('menu_parent', $menu_options['menu_parent']);
             $input->setOption('menu_link_desc', $menu_options['menu_link_desc']);
         }
     }
 }