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 / field / formatter.twig
index a2b0ad150e20fe6dae1a4ceef95e1c9a3c5632e4..f052902c5495b40de8eaaaa6d464cc9d8dbf9d4f 100644 (file)
@@ -4,7 +4,9 @@ namespace Drupal\{{ machine_name }}\Plugin\Field\FieldFormatter;
 
 use Drupal\Core\Field\FieldItemListInterface;
 use Drupal\Core\Field\FormatterBase;
+{% if configurable %}
 use Drupal\Core\Form\FormStateInterface;
+{% endif %}
 
 /**
  * Plugin implementation of the '{{ plugin_label }}' formatter.
@@ -19,13 +21,13 @@ use Drupal\Core\Form\FormStateInterface;
  */
 class {{ class }} extends FormatterBase {
 
+{% if configurable %}
   /**
    * {@inheritdoc}
    */
   public static function defaultSettings() {
     return [
-      'prefix' => '',
-      'suffix' => '',
+      'foo' => 'bar',
     ] + parent::defaultSettings();
   }
 
@@ -33,18 +35,11 @@ class {{ class }} extends FormatterBase {
    * {@inheritdoc}
    */
   public function settingsForm(array $form, FormStateInterface $form_state) {
-    $settings = $this->getSettings();
 
-    $elements['prefix'] = [
+    $elements['foo'] = [
       '#type' => 'textfield',
-      '#title' => $this->t('Prefix'),
-      '#default_value' => $settings['prefix'],
-    ];
-
-    $elements['suffix'] = [
-      '#type' => 'textfield',
-      '#title' => $this->t('Suffix'),
-      '#default_value' => $settings['suffix'],
+      '#title' => $this->t('Foo'),
+      '#default_value' => $this->getSetting('foo'),
     ];
 
     return $elements;
@@ -54,32 +49,21 @@ class {{ class }} extends FormatterBase {
    * {@inheritdoc}
    */
   public function settingsSummary() {
-    $settings = $this->getSettings();
-    $summary = [];
-
-    if ($settings['prefix']) {
-      $summary[] = $this->t('Prefix: @prefix', ['@prefix' => $settings['prefix']]);
-    }
-    if ($settings['suffix']) {
-      $summary[] = $this->t('Suffix: @suffix', ['@suffix' => $settings['suffix']]);
-    }
-
+    $summary[] = $this->t('Foo: @foo', ['@foo' => $this->getSetting('foo')]);
     return $summary;
   }
 
+{% endif %}
   /**
    * {@inheritdoc}
    */
   public function viewElements(FieldItemListInterface $items, $langcode) {
     $element = [];
-    $settings = $this->getSettings();
 
     foreach ($items as $delta => $item) {
       $element[$delta] = [
         '#type' => 'item',
         '#markup' => $item->value,
-        '#field_prefix' => $settings['prefix'],
-        '#field_suffix' => $settings['suffix'],
       ];
     }