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.
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' => 'field_maxy8', 'type' => 'list_boolean', 'settings' => array( 'text_processing' => 0, ), 'widget' => array('type' => 'options_onoff'), 'settings' => array( 'allowed_values' => array( '0' => 'No', '1' => 'Yes', ), ) ); $field = field_create_field($field); $instance = array( 'field_name' => 'field_maxy8', 'required' => 'true', 'label' => 'Maxy 8', 'description' => st('Maxy 8'), 'entity_type' => 'node', 'bundle' => 'article', 'display' => array( 'teaser' => array( 'label' => 'hidden', 'type' => 'hidden', ), 'default' => array( 'label' => 'hidden', 'type' => 'hidden', ), ), ); field_create_instance($instance);
In order to use this you'll need to:
1) Put it in a
2) Put it in a
3) Save it, and run
UPDB through Drush