function autocomplete_deluxe_field_widget_form in Autocomplete Deluxe 7.2
Same name and namespace in other branches
- 7 autocomplete_deluxe.module \autocomplete_deluxe_field_widget_form()
Implements hook_field_widget_form().
File
- ./
autocomplete_deluxe.module, line 266 - Define enhanced autocomplete wdiget.
Code
function autocomplete_deluxe_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
global $base_url;
if (isset($instance['widget']['settings']['show_link']) && !empty($instance['widget']['settings']['show_link']) && user_access('administer taxonomy')) {
$vocabulary = $field['settings']['allowed_values'][0]['vocabulary'];
$suffix = '<a target="_blank" href="' . $base_url . '/admin/structure/taxonomy/' . $vocabulary . '">' . t('Manage terms') . '</a>';
}
else {
$suffix = '';
}
$element += array(
'#type' => 'autocomplete_deluxe',
'#size' => $instance['widget']['settings']['size'],
'#limit' => isset($instance['widget']['settings']['limit']) ? $instance['widget']['settings']['limit'] : 10,
'#min_length' => isset($instance['widget']['settings']['min_length']) ? $instance['widget']['settings']['min_length'] : 0,
'#use_synonyms' => isset($instance['widget']['settings']['use_synonyms']) ? $instance['widget']['settings']['use_synonyms'] : 0,
'#delimiter' => isset($instance['widget']['settings']['delimiter']) ? $instance['widget']['settings']['delimiter'] : '',
'#not_found_message' => isset($instance['widget']['settings']['not_found_message']) ? $instance['widget']['settings']['not_found_message'] : t("The term '@term' will be added."),
'#suffix' => $suffix,
);
$multiple = $field['cardinality'] > 1 || $field['cardinality'] == FIELD_CARDINALITY_UNLIMITED ? TRUE : FALSE;
$tags = array();
foreach ($items as $item) {
$tags[$item['tid']] = isset($item['taxonomy_term']) ? $item['taxonomy_term'] : taxonomy_term_load($item['tid']);
}
$element['#element_validate'] = array(
'taxonomy_autocomplete_validate',
);
$element += array(
'#multiple' => $multiple,
'#autocomplete_deluxe_path' => url($instance['widget']['settings']['autocomplete_deluxe_path'] . '/' . $field['field_name'], array(
'absolute' => TRUE,
)),
'#default_value' => autocomplete_deluxe_taxonomy_implode_tags($tags),
);
return $element;
}