I'm trying to add a simple checkbox in a Drupal 8 Entity Form that displays like the old Form API:
$form['approved'] = [ '#type' => 'checkbox', '#title' => t('Approved'), '#description' => t('Check this to indicate this person is approved for membership'), ];
Using D8 style field definitions, this should be something like
$fields['approved'] = BaseFieldDefinition::create('boolean') ->setLabel(t('Approved')) ->setDescription(t('Volunteer is approved for trusted work.')) ->setSettings(array( 'display_label' => TRUE, )) ->setDisplayOptions('view', array( 'type' => 'unicode-yes-no', 'weight' => -3, )) ->setDisplayOptions('form', array( 'type' => 'boolean_checkbox', 'weight' => -3, )) ->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('view', TRUE);
This doesn't quite work; I'm getting a checkbox with the label "On".
How do I fix this? Also has anybody gathered the various parameters used for setDisplayOptions() in one place and documented how these map to the Form API and the Render API? I've been looking at the sources in core/lib/Drupal/Core, and I'm not finding much. And there isn't even a test for the boolean_checkbox widget, so no code to look at there either.