6a5cfada4ff6e3a29a7b9c2a33ac11bd99922384
[yaffs-website] / vendor / chi-teck / drupal-code-generator / src / Command / Drupal_8 / Form / Base.php
1 <?php
2
3 namespace DrupalCodeGenerator\Command\Drupal_8\Form;
4
5 use DrupalCodeGenerator\Command\BaseGenerator;
6 use DrupalCodeGenerator\Utils;
7 use Symfony\Component\Console\Input\InputInterface;
8 use Symfony\Component\Console\Output\OutputInterface;
9 use Symfony\Component\Console\Question\ConfirmationQuestion;
10 use Symfony\Component\Console\Question\Question;
11
12 /**
13  * Base class for Drupal 8 form generators.
14  */
15 abstract class Base extends BaseGenerator {
16
17   /**
18    * {@inheritdoc}
19    */
20   protected function doInteract(InputInterface $input, OutputInterface $output, $options) {
21     $questions = Utils::defaultQuestions();
22     $questions['class'] = new Question('Class', $options['default_class']);
23     $questions['form_id'] = new Question('Form ID', $options['default_form_id']);
24
25     $questions['route'] = new ConfirmationQuestion('Would you like to create a route for this form?');
26     $vars = $this->collectVars($input, $output, $questions);
27
28     if ($vars['route']) {
29       $route_path = '/' . str_replace('_', '-', $vars['machine_name']) . '/example';
30       $route_questions['route_name'] = new Question('Route name', '{machine_name}.example');
31       $route_questions['route_path'] = new Question('Route path', $route_path);
32       $route_questions['route_title'] = new Question('Route title', 'Example');
33       $route_questions['route_permission'] = new Question('Route permission', $options['default_permission']);
34
35       $this->collectVars($input, $output, $route_questions, $vars);
36       $this->addFile()
37         ->path('{machine_name}.routing.yml')
38         ->template('d8/form/route.twig')
39         ->action('append');
40     }
41
42     $this->addFile()
43       ->path('src/Form/{class}.php')
44       ->template($options['template']);
45   }
46
47 }