3 namespace DrupalCodeGenerator\Command\Drupal_8\Plugin;
5 use DrupalCodeGenerator\Command\BaseGenerator;
6 use DrupalCodeGenerator\Utils;
7 use Symfony\Component\Console\Input\InputInterface;
8 use Symfony\Component\Console\Output\OutputInterface;
9 use Symfony\Component\Console\Question\ConfirmationQuestion;
10 use Symfony\Component\Console\Question\Question;
13 * Implements d8:plugin:entity-reference-selection command.
15 class EntityReferenceSelection extends BaseGenerator {
17 protected $name = 'd8:plugin:entity-reference-selection';
18 protected $description = 'Generates entity reference selection plugin';
19 protected $alias = 'entity-reference-selection';
24 protected function interact(InputInterface $input, OutputInterface $output) {
27 'comment' => 'Drupal\comment\Plugin\EntityReferenceSelection\CommentSelection',
28 'file' => 'Drupal\file\Plugin\EntityReferenceSelection\FileSelection',
29 'node' => 'Drupal\node\Plugin\EntityReferenceSelection\NodeSelection',
30 'taxonomy_term' => 'Drupal\taxonomy\Plugin\EntityReferenceSelection\TermSelection',
31 'user' => 'Drupal\user\Plugin\EntityReferenceSelection\UserSelection',
34 $questions = Utils::defaultQuestions();
36 $questions['entity_type'] = new Question('Entity type that can be referenced by this plugin', 'node');
37 $questions['entity_type']->setValidator([Utils::class, 'validateMachineName']);
38 $questions['entity_type']->setAutocompleterValues(array_keys($base_classes));
40 $questions['plugin_label'] = new Question('Plugin label', 'Advanced {entity_type} selection');
41 $questions['plugin_label']->setValidator([Utils::class, 'validateRequired']);
43 $questions['plugin_id'] = new Question('Plugin ID', [Utils::class, 'defaultPluginId']);
44 $questions['plugin_id']->setValidator([Utils::class, 'validateMachineName']);
46 $questions['configurable'] = new ConfirmationQuestion('Provide additional plugin configuration?', FALSE);
48 $default_class = function ($vars) {
49 return Utils::camelize($vars['machine_name'] . '_' . $vars['entity_type']) . 'Selection';
51 $questions['class'] = new Question('Class', $default_class);
53 $vars = &$this->collectVars($input, $output, $questions);
55 if (isset($base_classes[$vars['entity_type']])) {
56 $vars['base_class_full'] = $base_classes[$vars['entity_type']];
59 $vars['base_class_full'] = 'Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection';
62 $vars['base_class'] = explode('EntityReferenceSelection\\', $vars['base_class_full'])[1];
65 ->path('src/Plugin/EntityReferenceSelection/{class}.php')
66 ->template('d8/plugin/entity-reference-selection.twig');
69 ->path('config/schema/{machine_name}.schema.yml')
70 ->template('d8/plugin/entity-reference-selection-schema.twig')