I've only made a few modules before, but I've had no trouble putting in text fields, images, and files. But trying to put in a radio button is proving difficult. In my .install file I have a function that returns an array of $fields, and another that returns an array of $instances. I believe my $fields are correct, I can see the table in the database, but I only get one radio button, and that's the "N/A" default. My assumption is my $instance is incorrect, specifically that there should be some 'options' array that feeds the options for each of the radio buttons. Does anyone know of a tutorial or sample of code that shows how to create an instance of a radio button (options_buttons) and how to load in the options?
My snippet of code is below:
$instances['course_catalog_course_availability'] = array(
'field_name' => 'course_catalog_course_availability',
'label' => $t('Course availability'),
'description' => $t('Course availability'),
'widget' => array(
'settings' => array(),
'type' => 'options_buttons',
),
'settings' => array(
'text_processing' => 0,
),
);
What I'm looking for is something like:
( ) N/A
( ) Available
( ) Unavilable
Where the parenthesis represent radio buttons.
Thanks
(LATER that same life....)
Got it. Although the $fields array creates the space in the database and the $instances array links that database to the values of your content types, it is the $fields array which gets the values assigned. The below snippets worked. Note the required => TRUE in the $instances array is necessary to make the "N/A" heading disappear. Adding 'cardinality' => -1, in the $fields array converts radio buttons to check boxes.
$fields['course_catalog_course_avail'] = array(
'field_name' => 'course_catalog_course_avail',
'type' => 'list_boolean',
'settings' => array(
'allowed_values' => array(
0 => 'No',
1 => 'Yes',
),
),
);
$instances['course_catalog_course_avail'] = array(
'field_name' => 'course_catalog_course_avail',
'label' => $t('Course availability'),
'description' => $t('Course availability'),
'widget' => array(
'settings' => array(),
'type' => 'options_buttons',
),
'settings' => array(
'text_processing' => 0,
),
'required' => TRUE,
);