Security update for Core, with self-updated composer
[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
19 class EntityContentCommand extends EntityCommand
20 {
21     /**
22      * @var ChainQueue
23      */
24     protected $chainQueue;
25
26     /**
27      * @var EntityContentGenerator
28      */
29     protected $generator;
30
31     /**
32      * @var StringConverter
33      */
34     protected $stringConverter;
35
36     /**
37      * @var Manager
38      */
39     protected $extensionManager;
40
41     /**
42      * @var Validator
43      */
44     protected $validator;
45
46     /**
47      * EntityContentCommand constructor.
48      *
49      * @param ChainQueue             $chainQueue
50      * @param EntityContentGenerator $generator
51      * @param StringConverter        $stringConverter
52      * @param Manager                $extensionManager
53      * @param Validator              $validator
54      */
55     public function __construct(
56         ChainQueue $chainQueue,
57         EntityContentGenerator $generator,
58         StringConverter $stringConverter,
59         Manager $extensionManager,
60         Validator $validator
61     ) {
62         $this->chainQueue = $chainQueue;
63         $this->generator = $generator;
64         $this->stringConverter = $stringConverter;
65         $this->extensionManager = $extensionManager;
66         $this->validator = $validator;
67         parent::__construct();
68     }
69
70
71     /**
72      * {@inheritdoc}
73      */
74     protected function configure()
75     {
76         $this->setEntityType('EntityContent');
77         $this->setCommandName('generate:entity:content');
78         parent::configure();
79         $this->addOption(
80             'has-bundles',
81             null,
82             InputOption::VALUE_NONE,
83             $this->trans('commands.generate.entity.content.options.has-bundles')
84         );
85
86         $this->addOption(
87             'is-translatable',
88             null,
89             InputOption::VALUE_NONE,
90             $this->trans('commands.generate.entity.content.options.is-translatable')
91         );
92
93         $this->addOption(
94             'revisionable',
95             null,
96             InputOption::VALUE_NONE,
97             $this->trans('commands.generate.entity.content.options.revisionable')
98         )
99             ->setAliases(['geco']);
100     }
101
102     /**
103      * {@inheritdoc}
104      */
105     protected function interact(InputInterface $input, OutputInterface $output)
106     {
107         parent::interact($input, $output);
108
109         // --bundle-of option
110         $bundle_of = $input->getOption('has-bundles');
111         if (!$bundle_of) {
112             $bundle_of = $this->getIo()->confirm(
113                 $this->trans('commands.generate.entity.content.questions.has-bundles'),
114                 false
115             );
116             $input->setOption('has-bundles', $bundle_of);
117         }
118
119         // --is-translatable option
120         $is_translatable = $this->getIo()->confirm(
121             $this->trans('commands.generate.entity.content.questions.is-translatable'),
122             true
123         );
124         $input->setOption('is-translatable', $is_translatable);
125
126         // --revisionable option
127         $revisionable = $this->getIo()->confirm(
128             $this->trans('commands.generate.entity.content.questions.revisionable'),
129             true
130         );
131         $input->setOption('revisionable', $revisionable);
132     }
133
134     /**
135      * {@inheritdoc}
136      */
137     protected function execute(InputInterface $input, OutputInterface $output)
138     {
139         $module = $input->getOption('module');
140         $entity_class = $input->getOption('entity-class');
141         $entity_name = $input->getOption('entity-name');
142         $label = $input->getOption('label');
143         $has_bundles = $input->getOption('has-bundles');
144         $base_path = $input->getOption('base-path');
145         $learning = $input->hasOption('learning')?$input->getOption('learning'):false;
146         $bundle_entity_type = $has_bundles ? $entity_name . '_type' : null;
147         $is_translatable = $input->hasOption('is-translatable') ? $input->getOption('is-translatable') : true;
148         $revisionable = $input->hasOption('revisionable') ? $input->getOption('revisionable') : false;
149
150         $generator = $this->generator;
151
152         $generator->setIo($this->getIo());
153         //@TODO:
154         //$generator->setLearning($learning);
155
156         $generator->generate([
157             'module' => $module,
158             'entity_name' => $entity_name,
159             'entity_class' => $entity_class,
160             'label' => $label,
161             'bundle_entity_type' => $bundle_entity_type,
162             'base_path' => $base_path,
163             'is_translatable' => $is_translatable,
164             'revisionable' => $revisionable,
165         ]);
166
167         if ($has_bundles) {
168             $this->chainQueue->addCommand(
169                 'generate:entity:config', [
170                 '--module' => $module,
171                 '--entity-class' => $entity_class . 'Type',
172                 '--entity-name' => $entity_name . '_type',
173                 '--label' => $label . ' type',
174                 '--bundle-of' => $entity_name
175                 ]
176             );
177         }
178     }
179 }