function select_or_other_content_allowed_values_alter in Select (or other) 6.2
Implementation of hook_content_allowed_values_alter().
Integrate with CCK for properly displaying key|value options.
File
- ./
select_or_other.module, line 661 - The Select (or other) module.
Code
function select_or_other_content_allowed_values_alter(&$allowed_values, $field) {
// Test the operation to avoid validation error with text field validation on saving.
if ($field['widget']['module'] == 'select_or_other' && (empty($_POST['op']) || !empty($_POST['op']) && $_POST['op'] != t('Save')) && (empty($_POST['op']) || !empty($_POST['op']) && $_POST['op'] != t('Delete'))) {
$list = explode("\n", $field['widget']['available_options']);
$list = array_map('trim', $list);
$list = array_filter($list, 'strlen');
foreach ($list as $option) {
// Sanitize the user input with a permissive filter.
$option = content_filter_xss($option);
if (strpos($option, '|') !== FALSE) {
list($key, $value) = explode('|', $option);
$allowed_values[$key] = isset($value) && $value !== '' ? html_entity_decode($value) : $key;
}
else {
$allowed_values[$option] = html_entity_decode($option);
}
}
// Add the other value to the allowed values.
if (!empty($_POST[$field['field_name']]['other'])) {
// Sanitize the user input with a permissive filter.
$value = check_plain(content_filter_xss(trim($_POST[$field['field_name']]['other'])));
if ($value !== '') {
$allowed_values[$value] = $value;
}
}
}
}