Patched to Drupal 8.4.8 level. See https://www.drupal.org/sa-core-2018-004 and patch...
[yaffs-website] / vendor / drupal / console / src / Generator / PermissionGenerator.php
1 <?php
2
3 /**
4  * @file
5  * Contains Drupal\Console\Generator\PermissionGenerator.
6  */
7
8 namespace Drupal\Console\Generator;
9
10 use Drupal\Console\Core\Generator\Generator;
11 use Drupal\Console\Extension\Manager;
12
13 class PermissionGenerator extends Generator
14 {
15     /**
16      * @var Manager
17      */
18     protected $extensionManager;
19
20     /**
21      * PermissionGenerator constructor.
22      *
23      * @param Manager $extensionManager
24      */
25     public function __construct(
26         Manager $extensionManager
27     ) {
28         $this->extensionManager = $extensionManager;
29     }
30
31     /**
32      * {@inheritdoc}
33      */
34     public function generate(array $parameters)
35     {
36         $module = $parameters['module_name'];
37         $learning = $parameters['learning'];
38
39         $this->renderFile(
40             'module/permission.yml.twig',
41             $this->extensionManager->getModule($module)->getPath() . '/' . $module . '.permissions.yml',
42             $parameters,
43             FILE_APPEND
44         );
45
46         $content = $this->renderer->render(
47             'module/permission-routing.yml.twig',
48             $parameters
49         );
50
51         if ($learning) {
52             echo 'You can use this permission in the routing file like this:' . PHP_EOL;
53             echo $content;
54         }
55     }
56 }