I've added a lot of fields and field instances via a custom module to some prepared content types. field_create_field()
and field_create_instance()
work like a charm, not a single error. Every field then works as expected, EXCEPT for the checkbox field.
It appears at the right place, has the right label, BUT when it comes to node saving the checked checkbox simply won't save. Next time I edit the node it's unchecked again, no value got written to the database. What do I miss here?
$field = array(
'field' => array(
'field_name' => 'MYFIELD',
'label' => 'Set as default',
'type' => 'list_boolean',
),
'instance' => array(
'field_name' => 'MYFIELD',
'entity_type' => 'node',
'bundle' => 'MYBUNDLE',
'label' => 'Set as default',
'widget' => array(
'type' => 'options_onoff',
'settings' => array(
'display_label' => TRUE,
),
),
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'hidden',
),
),
),
);
field_create_field($field['field']);
field_create_instance($field['instance']);
'module' => 'options',
to$field['instance']['widget']
. and'module' => 'list'
to$field['instance']
. You're also missing'active' => 1
and a few other things looking at it. Diff yours against this one (which works)'allowed_values'
to$field['field]
. Thanks for the pastebin!