Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / src / Command / Drupal_8 / Plugin / Filter.php
diff --git a/vendor/chi-teck/drupal-code-generator/src/Command/Drupal_8/Plugin/Filter.php b/vendor/chi-teck/drupal-code-generator/src/Command/Drupal_8/Plugin/Filter.php
new file mode 100644 (file)
index 0000000..93d28bd
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+
+namespace DrupalCodeGenerator\Command\Drupal_8\Plugin;
+
+use DrupalCodeGenerator\Command\BaseGenerator;
+use DrupalCodeGenerator\Utils;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Question\ChoiceQuestion;
+
+/**
+ * Implements d8:plugin:filter command.
+ */
+class Filter extends BaseGenerator {
+
+  protected $name = 'd8:plugin:filter';
+  protected $description = 'Generates filter plugin';
+  protected $alias = 'filter';
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function interact(InputInterface $input, OutputInterface $output) {
+    $questions = Utils::defaultPluginQuestions();
+
+    $filter_types = [
+      'TYPE_HTML_RESTRICTOR' => 'HTML restrictor',
+      'TYPE_MARKUP_LANGUAGE' => 'Markup language',
+      'TYPE_TRANSFORM_IRREVERSIBLE' => 'Irreversible transformation',
+      'TYPE_TRANSFORM_REVERSIBLE' => 'Reversible transformation',
+    ];
+    $choices = array_values($filter_types);
+    // Start choices list form '1'.
+    array_unshift($choices, NULL);
+    unset($choices[0]);
+    $questions['filter_type'] = new ChoiceQuestion('Filter type', $choices);
+
+    $vars = &$this->collectVars($input, $output, $questions);
+    $vars['class'] = Utils::camelize($vars['plugin_label']);
+    $vars['filter_type'] = array_search($vars['filter_type'], $filter_types);
+
+    $this->addFile()
+      ->path('src/Plugin/Filter/{class}.php')
+      ->template('d8/plugin/filter.twig');
+
+    $this->addFile()
+      ->path('config/schema/{machine_name}.schema.yml')
+      ->template('d8/plugin/filter-schema.twig')
+      ->action('append');
+  }
+
+}