93d28bdff769f786d239cfd48093b25f223554da
[yaffs-website] / vendor / chi-teck / drupal-code-generator / src / Command / Drupal_8 / Plugin / Filter.php
1 <?php
2
3 namespace DrupalCodeGenerator\Command\Drupal_8\Plugin;
4
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\ChoiceQuestion;
10
11 /**
12  * Implements d8:plugin:filter command.
13  */
14 class Filter extends BaseGenerator {
15
16   protected $name = 'd8:plugin:filter';
17   protected $description = 'Generates filter plugin';
18   protected $alias = 'filter';
19
20   /**
21    * {@inheritdoc}
22    */
23   protected function interact(InputInterface $input, OutputInterface $output) {
24     $questions = Utils::defaultPluginQuestions();
25
26     $filter_types = [
27       'TYPE_HTML_RESTRICTOR' => 'HTML restrictor',
28       'TYPE_MARKUP_LANGUAGE' => 'Markup language',
29       'TYPE_TRANSFORM_IRREVERSIBLE' => 'Irreversible transformation',
30       'TYPE_TRANSFORM_REVERSIBLE' => 'Reversible transformation',
31     ];
32     $choices = array_values($filter_types);
33     // Start choices list form '1'.
34     array_unshift($choices, NULL);
35     unset($choices[0]);
36     $questions['filter_type'] = new ChoiceQuestion('Filter type', $choices);
37
38     $vars = &$this->collectVars($input, $output, $questions);
39     $vars['class'] = Utils::camelize($vars['plugin_label']);
40     $vars['filter_type'] = array_search($vars['filter_type'], $filter_types);
41
42     $this->addFile()
43       ->path('src/Plugin/Filter/{class}.php')
44       ->template('d8/plugin/filter.twig');
45
46     $this->addFile()
47       ->path('config/schema/{machine_name}.schema.yml')
48       ->template('d8/plugin/filter-schema.twig')
49       ->action('append');
50   }
51
52 }