Skip to content

Commit 31757ed

Browse files
committed
Added d8:component:yml:routing command.
1 parent a01204a commit 31757ed

File tree

6 files changed

+104
-1
lines changed

6 files changed

+104
-1
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace DrupalCodeGenerator\Commands\Drupal_8\Component\Yml;
4+
5+
use Symfony\Component\Console\Input\InputInterface;
6+
use Symfony\Component\Console\Output\OutputInterface;
7+
use DrupalCodeGenerator\Commands\BaseGenerator;
8+
9+
/**
10+
* Implements d8:component:routing-yml command.
11+
*/
12+
class Routing extends BaseGenerator {
13+
14+
protected $name = 'd8:component:yml:routing';
15+
protected $description = 'Generates a routing yml file';
16+
17+
/**
18+
* {@inheritdoc}
19+
*/
20+
protected function interact(InputInterface $input, OutputInterface $output) {
21+
22+
$questions = [
23+
'name' => ['Module name', [$this, 'defaultName']],
24+
'machine_name' => ['Module machine name', [$this, 'defaultMachineName']],
25+
];
26+
$vars = $this->collectVars($input, $output, $questions);
27+
28+
$vars['class'] = $this->human2class($vars['name'] . 'Controller');
29+
$this->files[$vars['machine_name'] . '.routing.yml'] = $this->render('d8/routing.yml.twig', $vars);
30+
}
31+
32+
}

src/Templates/d8/routing.yml.twig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{{ machine_name }}.reports:
2+
path: '/admin/reports/{{ machine_name }}'
3+
defaults:
4+
_controller: '\Drupal\{{ machine_name }}\Controller\{{ class }}::reports'
5+
_title: '{{ name }} report'
6+
requirements:
7+
_permission: 'access site reports'
8+
{{ machine_name }}.settings:
9+
path: '/admin/config/{{ machine_name }}/settings'
10+
defaults:
11+
_form: 'Drupal\{{ machine_name }}\Form\Settings'
12+
_title: '{{ name }} settings'
13+
requirements:
14+
_permission: 'administer {{ machine_name }} configuration'
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace DrupalCodeGenerator\Tests\Drupal_8\Component\Yml;
4+
5+
use DrupalCodeGenerator\Tests\GeneratorTestCase;
6+
7+
/**
8+
* Test for d8:component:yml:routing command.
9+
*/
10+
class Routing extends GeneratorTestCase {
11+
12+
/**
13+
* {@inheritdoc}
14+
*/
15+
public function setUp() {
16+
$this->class = 'Drupal_8\Component\Yml\Routing';
17+
$this->answers = [
18+
'Example',
19+
'example',
20+
];
21+
$this->target = 'example.routing.yml';
22+
$this->fixture = __DIR__ . '/_' . $this->target;
23+
24+
parent::setUp();
25+
}
26+
27+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
example.reports:
2+
path: '/admin/reports/example'
3+
defaults:
4+
_controller: '\Drupal\example\Controller\ExampleController::reports'
5+
_title: 'Example report'
6+
requirements:
7+
_permission: 'access site reports'
8+
example.settings:
9+
path: '/admin/config/example/settings'
10+
defaults:
11+
_form: 'Drupal\example\Form\Settings'
12+
_title: 'Example settings'
13+
requirements:
14+
_permission: 'administer example configuration'

src/Tests/GeneratorsDiscoveryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
class GeneratorsDiscoveryTest extends \PHPUnit_Framework_TestCase {
1414

15-
const TOTAL_GENERATORS = 26;
15+
const TOTAL_GENERATORS = 27;
1616

1717
/**
1818
* Test callback.

src/Tests/integration-fixtures.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,22 @@
343343
'- example.libraries.yml',
344344
],
345345
],
346+
[
347+
'answers' => [
348+
'<comment>Drupal 8</comment>',
349+
'<comment>Component</comment>',
350+
'<comment>Yml</comment>',
351+
'Routing',
352+
'Example',
353+
'example',
354+
],
355+
'output' => [
356+
'Command: d8:component:yml:routing',
357+
'---------------------------------',
358+
'The following files have been created:',
359+
'- example.routing.yml',
360+
],
361+
],
346362
[
347363
'answers' => [
348364
'<comment>Drupal 8</comment>',

0 commit comments

Comments
 (0)