Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / chi-teck / drupal-code-generator / src / Command / Drupal_8 / Form / Base.php
index 6a5cfada4ff6e3a29a7b9c2a33ac11bd99922384..7937c8aebb14bc1637a7b85c24dde2d442d0050a 100644 (file)
@@ -20,16 +20,19 @@ abstract class Base extends BaseGenerator {
   protected function doInteract(InputInterface $input, OutputInterface $output, $options) {
     $questions = Utils::defaultQuestions();
     $questions['class'] = new Question('Class', $options['default_class']);
-    $questions['form_id'] = new Question('Form ID', $options['default_form_id']);
 
     $questions['route'] = new ConfirmationQuestion('Would you like to create a route for this form?');
-    $vars = $this->collectVars($input, $output, $questions);
+    $vars = &$this->collectVars($input, $output, $questions);
+    $raw_form_id = preg_replace('/_form/', '', Utils::camel2machine($vars['class']));
+    $vars['form_id'] = $vars['machine_name'] . '_' . $raw_form_id;
 
     if ($vars['route']) {
-      $route_path = '/' . str_replace('_', '-', $vars['machine_name']) . '/example';
-      $route_questions['route_name'] = new Question('Route name', '{machine_name}.example');
+      $default_path_prefix = isset($options['default_path_prefix']) ?
+        $options['default_path_prefix'] : '/' . $vars['machine_name'];
+      $route_path = str_replace('_', '-', $default_path_prefix . '/' . $raw_form_id);
+      $route_questions['route_name'] = new Question('Route name', '{machine_name}.' . $raw_form_id);
       $route_questions['route_path'] = new Question('Route path', $route_path);
-      $route_questions['route_title'] = new Question('Route title', 'Example');
+      $route_questions['route_title'] = new Question('Route title', Utils::machine2human($raw_form_id));
       $route_questions['route_permission'] = new Question('Route permission', $options['default_permission']);
 
       $this->collectVars($input, $output, $route_questions, $vars);