function cck_select_other_options in CCK Select Other 7
Same name and namespace in other branches
- 6 cck_select_other.module \cck_select_other_options()
- 7.2 cck_select_other.module \cck_select_other_options()
Retrieve options for the select list
Parameters
$field the field instance we're working with:
Return value
an array of options to pass into the Form API.
11 calls to cck_select_other_options()
- CCKSelectOtherAllowedValuesTest::testAllowedValues in tests/
cck_select_other.test - Fail validation or test allowed values for other option
- CCKSelectOtherBasicTest::testFailValidationForm in tests/
cck_select_other.test - Fail validation of node edit form, check option values TODO: I don't think I can resave the same form with drupalPost
- CCKSelectOtherBasicTest::testSelectFieldValue in tests/
cck_select_other.test - Modify node with a new value from select list options
- CCKSelectOtherMultipleFieldsTest::testMultipleField in tests/
cck_select_other.test - CCKSelectOtherMultipleValueListTest::setUp in tests/
cck_select_other.test - Implementation of setUp() method
File
- ./
cck_select_other.module, line 254 - Implements a select list widget that lets a user provide an alternate option.
Code
function cck_select_other_options($field) {
if (!isset($field['widget'])) {
return array();
}
$options = eval($field['widget']['settings']['select_list_options_fieldset']['advanced_options']['select_list_options_php']);
if (empty($options)) {
$options_str = $field['widget']['settings']['select_list_options'];
if (!empty($options_str)) {
$options_arr = preg_split("/[\r]?[\n]/", $options_str);
if (count($options_arr) > 0) {
foreach ($options_arr as $option_str) {
$option_arr = preg_split("/\\|/", $option_str);
if (count($option_arr) == 2) {
$options[check_plain($option_arr[0])] = t('@option', array(
'@option' => $option_arr[1],
));
}
else {
$options[check_plain($option_arr[0])] = t('@option', array(
'@option' => $option_arr[0],
));
}
}
}
}
}
else {
foreach ($options as $key => $option) {
if (!is_numeric($key)) {
$key = check_plain($key);
}
$options[$key] = t('@option', array(
'@option' => $option,
));
}
}
if (!isset($options['other'])) {
$options['other'] = t('Other');
}
if (!$field['required']) {
$options = array(
'_none' => t('- None - '),
) + $options;
}
else {
$options = array(
'' => t('- Select a value -'),
) + $options;
}
return $options;
}