Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / plugin / views / field.twig
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/plugin/views/field.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/plugin/views/field.twig
new file mode 100644 (file)
index 0000000..e373cb4
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+
+namespace Drupal\{{ machine_name }}\Plugin\views\field;
+
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\views\Plugin\views\field\FieldPluginBase;
+use Drupal\views\ResultRow;
+
+/**
+ * Provides {{ plugin_label }} field handler.
+ *
+ * @ViewsField("{{ plugin_id }}")
+ */
+class {{ class }} extends FieldPluginBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function defineOptions() {
+    $options = parent::defineOptions();
+    $options['prefix'] = ['default' => ''];
+    $options['suffix'] = ['default' => ''];
+    return $options;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
+    parent::buildOptionsForm($form, $form_state);
+
+    $form['prefix'] = [
+      '#type' => 'textfield',
+      '#title' => $this->t('Prefix'),
+      '#default_value' => $this->options['prefix'],
+    ];
+
+    $form['suffix'] = [
+      '#type' => 'textfield',
+      '#title' => $this->t('Suffix'),
+      '#default_value' => $this->options['suffix'],
+    ];
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function render(ResultRow $values) {
+    return $this->options['prefix'] . parent::render($values) . $this->options['suffix'];
+  }
+
+}