Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / src / Generator / EntityConfigGenerator.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Generator\EntityConfigGenerator.
6  */
7
8 namespace Drupal\Console\Generator;
9
10 use Drupal\Console\Core\Generator\Generator;
11 use Drupal\Console\Extension\Manager;
12
13 class EntityConfigGenerator extends Generator
14 {
15     /**
16      * @var Manager
17      */
18     protected $extensionManager;
19
20     /**
21      * EntityConfigGenerator constructor.
22      *
23      * @param Manager $extensionManager
24      */
25     public function __construct(
26         Manager $extensionManager
27     ) {
28         $this->extensionManager = $extensionManager;
29     }
30
31
32     /**
33      * Generator Entity.
34      *
35      * @param string $module       Module name
36      * @param string $entity_name  Entity machine name
37      * @param string $entity_class Entity class name
38      * @param string $label        Entity label
39      * @param string $base_path    Base path
40      * @param string $bundle_of    Entity machine name of the content entity this config entity acts as a bundle for.
41      */
42     public function generate($module, $entity_name, $entity_class, $label, $base_path, $bundle_of = null)
43     {
44         $parameters = [
45           'module' => $module,
46           'entity_name' => $entity_name,
47           'entity_class' => $entity_class,
48           'label' => $label,
49           'bundle_of' => $bundle_of,
50           'base_path' => $base_path,
51         ];
52
53         $this->renderFile(
54             'module/config/schema/entity.schema.yml.twig',
55             $this->extensionManager->getModule($module)->getPath().'/config/schema/'.$entity_name.'.schema.yml',
56             $parameters
57         );
58
59         $this->renderFile(
60             'module/links.menu-entity-config.yml.twig',
61             $this->extensionManager->getModule($module)->getPath().'/'.$module.'.links.menu.yml',
62             $parameters,
63             FILE_APPEND
64         );
65
66         $this->renderFile(
67             'module/links.action-entity.yml.twig',
68             $this->extensionManager->getModule($module)->getPath().'/'.$module.'.links.action.yml',
69             $parameters,
70             FILE_APPEND
71         );
72
73         $this->renderFile(
74             'module/src/Entity/interface-entity.php.twig',
75             $this->extensionManager->getModule($module)->getEntityPath().'/'.$entity_class.'Interface.php',
76             $parameters
77         );
78
79         $this->renderFile(
80             'module/src/Entity/entity.php.twig',
81             $this->extensionManager->getModule($module)->getEntityPath().'/'.$entity_class.'.php',
82             $parameters
83         );
84
85         $this->renderFile(
86             'module/src/entity-route-provider.php.twig',
87             $this->extensionManager->getModule($module)->getSourcePath().'/'.$entity_class.'HtmlRouteProvider.php',
88             $parameters
89         );
90
91         $this->renderFile(
92             'module/src/Form/entity.php.twig',
93             $this->extensionManager->getModule($module)->getFormPath().'/'.$entity_class.'Form.php',
94             $parameters
95         );
96
97         $this->renderFile(
98             'module/src/Form/entity-delete.php.twig',
99             $this->extensionManager->getModule($module)->getFormPath().'/'.$entity_class.'DeleteForm.php',
100             $parameters
101         );
102
103         $this->renderFile(
104             'module/src/entity-listbuilder.php.twig',
105             $this->extensionManager->getModule($module)->getSourcePath().'/'.$entity_class.'ListBuilder.php',
106             $parameters
107         );
108     }
109 }