From 89eadd72867da2d99c041a21acaff4357b5aab28 Mon Sep 17 00:00:00 2001
From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org>
Date: Mon, 29 Feb 2016 15:32:23 +0900
Subject: [PATCH] Issue #2671446 by heykarthikwithu, mikeker: The Boolean field
 formatter does not provide a settings summary

---
 .../Field/FieldFormatter/BooleanFormatter.php | 24 +++++++++++++++++++
 .../Boolean/BooleanFormatterSettingsTest.php  |  6 +++++
 2 files changed, 30 insertions(+)

diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/BooleanFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/BooleanFormatter.php
index 74c7523f1727..be7b94a5f8b2 100644
--- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/BooleanFormatter.php
+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/BooleanFormatter.php
@@ -114,6 +114,30 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
     return $form;
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function settingsSummary() {
+    $summary = [];
+    $setting = $this->getSetting('format');
+
+    if ($setting == 'custom') {
+      $summary[] = $this->t('Custom text: @true_label / @false_label', [
+        '@true_label' => $this->getSetting('format_custom_true'),
+        '@false_label' => $this->getSetting('format_custom_false'),
+      ]);
+    }
+    else {
+      $formats = $this->getOutputFormats();
+      $summary[] = $this->t('Display: @true_label / @false_label', [
+        '@true_label' => $formats[$setting][0],
+        '@false_label' => $formats[$setting][1],
+      ]);
+    }
+
+    return $summary;
+  }
+
   /**
    * {@inheritdoc}
    */
diff --git a/core/modules/field/src/Tests/Boolean/BooleanFormatterSettingsTest.php b/core/modules/field/src/Tests/Boolean/BooleanFormatterSettingsTest.php
index 8c5146b49e35..ce2ba0742683 100644
--- a/core/modules/field/src/Tests/Boolean/BooleanFormatterSettingsTest.php
+++ b/core/modules/field/src/Tests/Boolean/BooleanFormatterSettingsTest.php
@@ -125,6 +125,12 @@ function testBooleanFormatterSettings() {
       }
       $this->assertText(SafeMarkup::format($default, array('@on' => $values[0], '@off' => $values[1])));
     }
+
+    foreach ($settings as $values) {
+      $this->drupalGet('admin/structure/types/manage/' . $this->bundle . '/display');
+      $result = $this->xpath('//div[contains(@class, :class) and contains(text(), :text)]', [':class' => 'field-plugin-summary', ':text' => 'Display: TRUE / FALSE']);
+      $this->assertEqual(count($result), 1, "Boolean formatter settings summary exist.");
+    }
   }
 
 }
-- 
GitLab