BooleanCheckboxWidget.php in Zircon Profile 8.0        
                          
                  
                        
  
  
  
File
  core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/BooleanCheckboxWidget.php
  
    View source  
  <?php
namespace Drupal\Core\Field\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
class BooleanCheckboxWidget extends WidgetBase {
  
  public static function defaultSettings() {
    return array(
      'display_label' => FALSE,
    ) + parent::defaultSettings();
  }
  
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $element['display_label'] = array(
      '#type' => 'checkbox',
      '#title' => t('Use field label instead of the "On label" as label'),
      '#default_value' => $this
        ->getSetting('display_label'),
      '#weight' => -1,
    );
    return $element;
  }
  
  public function settingsSummary() {
    $summary = array();
    $display_label = $this
      ->getSetting('display_label');
    $summary[] = t('Use field label: @display_label', array(
      '@display_label' => $display_label ? t('Yes') : 'No',
    ));
    return $summary;
  }
  
  public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
    $element['value'] = $element + array(
      '#type' => 'checkbox',
      '#default_value' => !empty($items[0]->value),
    );
    
    if ($this
      ->getSetting('display_label')) {
      $element['value']['#title'] = $this->fieldDefinition
        ->getLabel();
    }
    else {
      $element['value']['#title'] = $this->fieldDefinition
        ->getSetting('on_label');
    }
    return $element;
  }
}