function chosen_pre_render_select in Chosen 7.3
Same name and namespace in other branches
- 7.2 chosen.module \chosen_pre_render_select()
Implementation of chosen_pre_render_select().
Atteches the library to the field and pass the fieldinstance related options.
TODO: Get the field specific configuration. TODO: Pass the correct cpnfiguration.
See also
pre_render
1 string reference to 'chosen_pre_render_select'
- chosen_element_info_alter in ./
chosen.module - Implements hook_element_info_alter().
File
- ./
chosen.module, line 386 - General functions and hook implementations.
Code
function chosen_pre_render_select($element) {
$field_info = isset($element['#field_name']) ? field_info_field($element['#field_name']) : FALSE;
$element_name = $element['#name'];
if (!empty($element['#multiple'])) {
// We need to add those brackets for multivalue fields.
$element_name = $element['#name'] . '[]';
}
$max_selected_options = FALSE;
if (isset($field_info['cardinality'])) {
if ($field_info['cardinality'] != FIELD_CARDINALITY_UNLIMITED) {
$max_selected_options = $field_info['cardinality'];
}
}
$element['#attached']['library'][] = array(
'chosen',
'drupal.chosen',
);
$element['#attached']['js'][] = array(
'data' => array(
'chosen' => array(
'multiple' => array(
$element_name => isset($element['#multiple']) ? $element['#multiple'] : FALSE,
),
'max_selected_options' => array(
$element_name => $max_selected_options,
),
),
),
'type' => 'setting',
);
return $element;
}