Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / src / Command / Generate / EntityContentCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Command\Generate\EntityContentCommand.
6  */
7
8 namespace Drupal\Console\Command\Generate;
9
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Input\InputOption;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Drupal\Console\Generator\EntityContentGenerator;
14 use Drupal\Console\Extension\Manager;
15 use Drupal\Console\Core\Utils\StringConverter;
16 use Drupal\Console\Core\Utils\ChainQueue;
17 use Drupal\Console\Utils\Validator;
18 use Drupal\Console\Core\Style\DrupalStyle;
19
20 class EntityContentCommand extends EntityCommand
21 {
22     /**
23      * @var ChainQueue
24      */
25     protected $chainQueue;
26
27     /**
28      * @var EntityContentGenerator
29      */
30     protected $generator;
31
32     /**
33      * @var StringConverter
34      */
35     protected $stringConverter;
36
37     /**
38      * @var Manager
39      */
40     protected $extensionManager;
41
42     /**
43      * @var Validator
44      */
45     protected $validator;
46
47     /**
48      * EntityContentCommand constructor.
49      *
50      * @param ChainQueue             $chainQueue
51      * @param EntityContentGenerator $generator
52      * @param StringConverter        $stringConverter
53      * @param Manager                $extensionManager
54      * @param Validator              $validator
55      */
56     public function __construct(
57         ChainQueue $chainQueue,
58         EntityContentGenerator $generator,
59         StringConverter $stringConverter,
60         Manager $extensionManager,
61         Validator $validator
62     ) {
63         $this->chainQueue = $chainQueue;
64         $this->generator = $generator;
65         $this->stringConverter = $stringConverter;
66         $this->extensionManager = $extensionManager;
67         $this->validator = $validator;
68         parent::__construct();
69     }
70
71
72     /**
73      * {@inheritdoc}
74      */
75     protected function configure()
76     {
77         $this->setEntityType('EntityContent');
78         $this->setCommandName('generate:entity:content');
79         parent::configure();
80
81         $this->addOption(
82             'has-bundles',
83             null,
84             InputOption::VALUE_NONE,
85             $this->trans('commands.generate.entity.content.options.has-bundles')
86         );
87
88         $this->addOption(
89             'is-translatable',
90             null,
91             InputOption::VALUE_NONE,
92             $this->trans('commands.generate.entity.content.options.is-translatable')
93         );
94
95         $this->addOption(
96             'revisionable',
97             null,
98             InputOption::VALUE_NONE,
99             $this->trans('commands.generate.entity.content.options.revisionable')
100         );
101     }
102
103     /**
104      * {@inheritdoc}
105      */
106     protected function interact(InputInterface $input, OutputInterface $output)
107     {
108         parent::interact($input, $output);
109         $io = new DrupalStyle($input, $output);
110
111         // --bundle-of option
112         $bundle_of = $input->getOption('has-bundles');
113         if (!$bundle_of) {
114             $bundle_of = $io->confirm(
115                 $this->trans('commands.generate.entity.content.questions.has-bundles'),
116                 false
117             );
118             $input->setOption('has-bundles', $bundle_of);
119         }
120
121         // --is-translatable option
122         $is_translatable = $io->confirm(
123             $this->trans('commands.generate.entity.content.questions.is-translatable'),
124             true
125         );
126         $input->setOption('is-translatable', $is_translatable);
127
128         // --revisionable option
129         $revisionable = $io->confirm(
130             $this->trans('commands.generate.entity.content.questions.revisionable'),
131             true
132         );
133         $input->setOption('revisionable', $revisionable);
134     }
135
136     /**
137      * {@inheritdoc}
138      */
139     protected function execute(InputInterface $input, OutputInterface $output)
140     {
141         $module = $input->getOption('module');
142         $entity_class = $input->getOption('entity-class');
143         $entity_name = $input->getOption('entity-name');
144         $label = $input->getOption('label');
145         $has_bundles = $input->getOption('has-bundles');
146         $base_path = $input->getOption('base-path');
147         $learning = $input->hasOption('learning')?$input->getOption('learning'):false;
148         $bundle_entity_name = $has_bundles ? $entity_name . '_type' : null;
149         $is_translatable = $input->hasOption('is-translatable') ? $input->getOption('is-translatable') : true;
150         $revisionable = $input->hasOption('revisionable') ? $input->getOption('revisionable') : false;
151
152         $io = new DrupalStyle($input, $output);
153         $generator = $this->generator;
154
155         $generator->setIo($io);
156         //@TODO:
157         //$generator->setLearning($learning);
158
159         $generator->generate($module, $entity_name, $entity_class, $label, $base_path, $is_translatable, $bundle_entity_name, $revisionable);
160
161         if ($has_bundles) {
162             $this->chainQueue->addCommand(
163                 'generate:entity:config', [
164                 '--module' => $module,
165                 '--entity-class' => $entity_class . 'Type',
166                 '--entity-name' => $entity_name . '_type',
167                 '--label' => $label . ' type',
168                 '--bundle-of' => $entity_name
169                 ]
170             );
171         }
172     }
173 }