Using field_create_field and field_create_instance to add a checkbox to a content type I've written the following update hook to add a field to a content type. In an ideal world I'd like that field to be a single on/off checkbox. However, the code I've written outputs three radio buttons - with options for Yes and No, as you'd expect - but one for NA, too. I don't really want my users to have an NA option. Any idea how to achieve this? I'm guessing it's either the widget or display attributes, but I don't know where to find a list of what options are available to me.



Update:

Marcel's suggestion worked just fine - it doesn't provide a checkbox, but it removes the NA option, and that's good enough for me. Adapted code is below - I've also made some changes to the rest of it that ensure the title and summary text are displayed properly in the editor UI: 

$field = array(                                       
  'field_name' =&gt; 'field_maxy8',    
  'type' =&gt; 'list_boolean',     
  'settings' =&gt; array(
    'text_processing' =&gt; 0,
  ),
  'widget' =&gt; array('type' =&gt; 'options_onoff'), 
  'settings' =&gt; array(
    'allowed_values' =&gt; array(
      '0' =&gt; 'No',
      '1' =&gt; 'Yes',
    ),
  ) 
);

$field = field_create_field($field);

$instance = array(
  'field_name' =&gt; 'field_maxy8',
  'required' =&gt; 'true', 
  'label' =&gt; 'Maxy 8',
  'description' =&gt; st('Maxy 8'),
  'entity_type' =&gt; 'node',
  'bundle' =&gt; 'article',
  'display' =&gt; array(
    'teaser' =&gt; array(
      'label' =&gt; 'hidden',
      'type' =&gt; 'hidden',
    ),
    'default' =&gt; array(
      'label' =&gt; 'hidden',
      'type' =&gt; 'hidden',
    ),
  ),
);

field_create_instance($instance);


In order to use this you'll need to: 

1) Put it in a &lt;modulename&gt;.install file

2) Put it in a hook_update_n function

3) Save it, and run UPDB through Drush
This is how you create a single boolean checkbox field and field instance: I have excluded checking whether the field or instance exists, for brevity.

field_create_field(array(
  'field_name'  =&gt; "my_bool",
  'type'        =&gt; 'list_boolean',
  'cardinality' =&gt; 1,
  'settings'    =&gt; array(
    'allowed_values' =&gt; array( 
      /*
       * The docs say that this is optional, but without it,
       * the value is never saved to the datbase (tested with Drupal 7.28)
       */
      0 =&gt; '',
      1 =&gt; '',
    ),
  ),
));

field_create_instance(array(
  'field_name'  =&gt; "my_bool",
  'entity_type' =&gt; 'taxonomy_term',             // or 'node'
  'bundle'      =&gt; 'my_vocabulary_machine_name, // or 'my_content_type'
  'label'       =&gt; t('My boolean checkbox'),
  'required'    =&gt; false,                       // because not ticking a checkbox omits the value from $_POST
  'display'     =&gt; array(
    'default' =&gt; array(
      'type' =&gt; 'hidden',                       // optional. I want to hide it
    ),
  ),
  'widget'      =&gt; array(
    'type'     =&gt; 'options_onoff',              // gives you a checkbox
    'settings' =&gt; array(
      'display_label' =&gt; 1,                     // uses 'My boolean checkbox' as the label next to the actual checkbox
    ),
  ),
));