Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / plugin / views / field.twig
1 <?php
2
3 namespace Drupal\{{ machine_name }}\Plugin\views\field;
4
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\views\Plugin\views\field\FieldPluginBase;
7 use Drupal\views\ResultRow;
8
9 /**
10  * Provides {{ plugin_label }} field handler.
11  *
12  * @ViewsField("{{ plugin_id }}")
13  */
14 class {{ class }} extends FieldPluginBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   protected function defineOptions() {
20     $options = parent::defineOptions();
21     $options['prefix'] = ['default' => ''];
22     $options['suffix'] = ['default' => ''];
23     return $options;
24   }
25
26   /**
27    * {@inheritdoc}
28    */
29   public function buildOptionsForm(&$form, FormStateInterface $form_state) {
30     parent::buildOptionsForm($form, $form_state);
31
32     $form['prefix'] = [
33       '#type' => 'textfield',
34       '#title' => $this->t('Prefix'),
35       '#default_value' => $this->options['prefix'],
36     ];
37
38     $form['suffix'] = [
39       '#type' => 'textfield',
40       '#title' => $this->t('Suffix'),
41       '#default_value' => $this->options['suffix'],
42     ];
43   }
44
45   /**
46    * {@inheritdoc}
47    */
48   public function render(ResultRow $values) {
49     return $this->options['prefix'] . parent::render($values) . $this->options['suffix'];
50   }
51
52 }