How to specify default options in a checkbox field using Field API I am trying to add a checkbox field to user entities using the FIELD API (in function MYMODULE_install() )

I can create the field, but I can't pre-load it with the desired default values.

Where my code is wrong ?

$default_notification_field_name = "field_notification_defaults";
if(!field_info_field($default_notification_field_name))   { // check if the field already exists.

    field_create_field(
        array(
            'field_name' =&gt; $default_notification_field_name,
            'cardinality' =&gt; FIELD_CARDINALITY_UNLIMITED,
            'type' =&gt; 'list_text',
            'settings' =&gt; array(
                'allowed_values' =&gt; array(
                    'group' =&gt; t('Groups to which you subscribe'),
                    'content' =&gt; t('Authored content'),
                    'comment' =&gt; t('Replies to your comments')
                )
            ),
        )
    );

    field_create_instance(
        array(
            'field_name' =&gt; $default_notification_field_name,
            'entity_type' =&gt; 'user',
            'bundle' =&gt; 'user',
            'label' =&gt; t('Default settings for notifications'), 
            'description' =&gt; t('Select the ​​default notification options for the groups to which you subscribe, the contents you send and the replies to (your) comments. These default options can then be modified on a per-group, content or comment bases.'),
            'required' =&gt; FALSE,
            'widget' =&gt; array(
                'type' =&gt; 'options_buttons',
            ),
            'default_value' =&gt; array('content','comment')
        )
    );
}
Try this for your instance creation:



field_create_instance(
  array(
    'field_name' =&gt; $default_notification_field_name,
    'entity_type' =&gt; 'user',
    'bundle' =&gt; 'user',
    'label' =&gt; t('Default settings for notifications'), 
    'description' =&gt; t('Select the ​​default notification options for the groups to which you subscribe, the contents you send and the replies to (your) comments. These default options can then be modified on a per-group, content or comment bases.'),
    'required' =&gt; FALSE,
    'widget' =&gt; array(
      'type' =&gt; 'options_buttons',
    ),
    'default_value' =&gt; array(
      0 =&gt; array(
        'value' =&gt; 'comment',
      ),
      1 =&gt; array(
        'value' =&gt; 'content',
      ),
    ),
  ));


To assist you in knowing the array structure, try this:


Install the devel module
Go to the page /devel/php on your site
Run this code to see all field information on your site:




// Show all fields.
dpm(field_info_fields());
// Show all field instances.
dpm(field_info_instances());