@@ -24,8 +24,9 @@ protected function configure()
24
24
->setDefinition (array (
25
25
new InputOption ('module ' ,'' ,InputOption::VALUE_REQUIRED , 'The name of the module ' ),
26
26
new InputOption ('class-name ' ,'' ,InputOption::VALUE_OPTIONAL , 'Controller name ' ),
27
+ new InputOption ('method-name ' ,'' ,InputOption::VALUE_OPTIONAL , 'The method name ' ),
28
+ new InputOption ('route ' ,'' ,InputOption::VALUE_OPTIONAL , 'The route path ' ),
27
29
new InputOption ('services ' ,'' ,InputOption::VALUE_OPTIONAL , 'Load services ' ),
28
- new InputOption ('routing ' , '' , InputOption::VALUE_NONE , 'Update routing ' ),
29
30
new InputOption ('test ' , '' , InputOption::VALUE_NONE , 'Generate test ' ),
30
31
))
31
32
->setDescription ('Generate controller ' )
@@ -49,15 +50,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
49
50
50
51
$ module = $ input ->getOption ('module ' );
51
52
$ class_name = $ input ->getOption ('class-name ' );
53
+ $ method_name = $ input ->getOption ('method-name ' );
54
+ $ route = $ input ->getOption ('route ' );
52
55
$ test = $ input ->getOption ('test ' );
53
56
$ services = $ input ->getOption ('services ' );
54
- $ update_routing = $ input ->getOption ('routing ' );
55
57
56
58
// @see use Drupal\AppConsole\Command\Helper\ServicesTrait::buildServices
57
59
$ build_services = $ this ->buildServices ($ services );
58
60
59
61
$ this ->getGenerator ()
60
- ->generate ($ module , $ class_name , $ test , $ build_services , $ update_routing );
62
+ ->generate ($ module , $ class_name , $ method_name , $ route , $ test , $ build_services );
61
63
62
64
$ errors = '' ;
63
65
$ dialog ->writeGeneratorSummary ($ output , $ errors );
@@ -82,13 +84,40 @@ protected function interact(InputInterface $input, OutputInterface $output)
82
84
// --class-name option
83
85
$ class_name = $ input ->getOption ('class-name ' );
84
86
if (!$ class_name ) {
85
- $ name = $ dialog ->ask (
87
+ $ class_name = $ dialog ->ask (
86
88
$ output ,
87
89
$ dialog ->getQuestion ('Enter the controller name ' , 'DefaultController ' ),
88
90
'DefaultController '
89
91
);
90
92
}
91
- $ input ->setOption ('class-name ' , $ name );
93
+ $ input ->setOption ('class-name ' , $ class_name );
94
+
95
+ // --method-name option & --route option
96
+ if ($ class_name != 'DefaultController ' ){
97
+ $ method_name = $ input ->getOption ('method-name ' );
98
+ if (!$ method_name ) {
99
+ $ method_name = $ dialog ->ask (
100
+ $ output ,
101
+ $ dialog ->getQuestion ('Enter the method name ' , 'index ' ),
102
+ 'index '
103
+ );
104
+ }
105
+
106
+ $ route = $ input ->getOption ('route ' );
107
+ if (!$ route ) {
108
+ $ route = $ dialog ->ask (
109
+ $ output ,
110
+ $ dialog ->getQuestion ('Enter the route path ' , $ method_name .'/index ' ),
111
+ $ method_name .'/index '
112
+ );
113
+ }
114
+ }
115
+ else {
116
+ $ method_name = 'hello ' ;
117
+ $ route = '/hello/{name} ' ;
118
+ }
119
+ $ input ->setOption ('method-name ' , $ method_name );
120
+ $ input ->setOption ('route ' , $ route );
92
121
93
122
// --test option
94
123
$ test = $ input ->getOption ('test ' );
@@ -105,17 +134,6 @@ protected function interact(InputInterface $input, OutputInterface $output)
105
134
// @see use Drupal\AppConsole\Command\Helper\ServicesTrait::servicesQuestion
106
135
$ services_collection = $ this ->servicesQuestion ($ input , $ output , $ dialog );
107
136
$ input ->setOption ('services ' , $ services_collection );
108
-
109
- // --routing option
110
- $ routing = $ input ->getOption ('routing ' );
111
- if (!$ routing && $ dialog ->askConfirmation (
112
- $ output ,
113
- $ dialog ->getQuestion ('Update routing file? ' , 'yes ' , '? ' ),
114
- true
115
- )) {
116
- $ routing = true ;
117
- }
118
- $ input ->setOption ('routing ' , $ routing );
119
137
}
120
138
121
139
/**
0 commit comments