I am developing a module that uses the flag api to send notifications, and I need to set ( in MYMODULE_install() ) a checkbox field to attach to user entities to allow for some user-level options.

I can create the field but no way I can set the default values (and I tried in tons of way) !

Where this 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' => $default_notification_field_name,
				'cardinality' => FIELD_CARDINALITY_UNLIMITED,
				'type' => 'list_text',
				'settings' => array(
					'allowed_values' => array(
						'group' => t('Groups to which you subscribe'),
						'content' => t('Authored content'),
						'comment' => t('Replies to your comments')
					)
				),
			)
		);

		field_create_instance(
			array(
				'field_name' => $default_notification_field_name,
				'entity_type' => 'user',
				'bundle' => 'user',
				'label' => t('Default settings for notifications'), 
				'description' => 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' => FALSE,
				'widget' => array(
					'type' => 'options_buttons',
				),
				'default_value' => array('content','comment')
			)
		);
	}

Comments

sylvaticus’s picture

(thanks to 'rooby')

    'default_value' => array(
      0 => array(
        'value' => 'comment',
      ),
      1 => array(
        'value' => 'content',
      ),
    ),