Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / plugin / filter.twig
1 <?php
2
3 namespace Drupal\{{ machine_name }}\Plugin\Filter;
4
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\filter\FilterProcessResult;
7 use Drupal\filter\Plugin\FilterBase;
8
9 /**
10  * Provides a '{{ plugin_label }}' filter.
11  *
12  * @Filter(
13  *   id = "{{ plugin_id }}",
14  *   title = @Translation("{{ plugin_label }}"),
15  *   type = Drupal\filter\Plugin\FilterInterface::{{ filter_type }},
16  *   settings = {
17  *     "example" = "foo",
18  *   },
19  *   weight = -10
20  * )
21  */
22 class {{ class }} extends FilterBase {
23
24   /**
25    * {@inheritdoc}
26    */
27   public function settingsForm(array $form, FormStateInterface $form_state) {
28     $form['example'] = [
29       '#type' => 'textfield',
30       '#title' => $this->t('Example'),
31       '#default_value' => $this->settings['example'],
32       '#description' => $this->t('Description of the setting.'),
33     ];
34     return $form;
35   }
36
37   /**
38    * {@inheritdoc}
39    */
40   public function process($text, $langcode) {
41     // @DCG Process text here.
42     $example = $this->settings['example'];
43     $text = str_replace($example, "<b>$example</b>", $text);
44     return new FilterProcessResult($text);
45   }
46
47   /**
48    * {@inheritdoc}
49    */
50   public function tips($long = FALSE) {
51     return $this->t('Some filter tips here.');
52   }
53
54 }