function content_taxonomy_autocomplete_form_field_ui_field_edit_form_alter in Content Taxonomy 7
Implements hook_form_ID_alter().
File
- ./
content_taxonomy_autocomplete.module, line 37
Code
function content_taxonomy_autocomplete_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) {
$field = $form['#field'];
$instance = $form['#instance'];
if ($instance['widget']['type'] == 'taxonomy_autocomplete' || $instance['widget']['type'] == 'active_tags_taxonomy_autocomplete' || $instance['widget']['type'] == 'autocomplete_deluxe_taxonomy' || $instance['widget']['type'] == 'entityreference_autocomplete' || $instance['widget']['type'] == 'entityreference_autocomplete_tags') {
// Add a setting form for validating new terms.
$options = array(
'allow' => t('Allow and insert new terms'),
'moderate' => t('Allow new terms and insert them into a separate vocabulary'),
'deny' => t('Deny any new terms'),
);
$form['instance']['widget']['settings']['content_taxonomy_autocomplete_new_terms'] = array(
'#type' => 'radios',
'#title' => t('Autocomplete settings'),
'#options' => $options,
'#default_value' => isset($instance['widget']['settings']['content_taxonomy_autocomplete_new_terms']) ? $instance['widget']['settings']['content_taxonomy_autocomplete_new_terms'] : 'allow',
'#description' => t('If option 2 is selected, re-save this settings form and afterwards select a second vocabulary for new terms in the field settings. In case the Autocomplete Deluxe widget is used, new terms can be hidden from the suggestion list.'),
);
}
// Show form for second vocabulary.
if (($instance['widget']['type'] == 'taxonomy_autocomplete' || $instance['widget']['type'] == 'active_tags_taxonomy_autocomplete' || $instance['widget']['type'] == 'autocomplete_deluxe_taxonomy' || $instance['widget']['type'] == 'entityreference_autocomplete' || $instance['widget']['type'] == 'entityreference_autocomplete_tags') && isset($form[$instance['field_name']]) && isset($instance['widget']['settings']['content_taxonomy_autocomplete_new_terms'])) {
// Initialize settings, if not set.
if (!isset($field['settings']['allowed_values'][1])) {
$field['settings']['allowed_values'][1] = array(
'vocabulary' => $field['settings']['allowed_values'][0]['vocabulary'],
'parent' => 0,
);
}
$vocabularies = taxonomy_get_vocabularies();
$options = array();
$options[''] = '---';
foreach ($vocabularies as $vocabulary) {
$options[$vocabulary->machine_name] = $vocabulary->name;
}
$form['field']['settings']['allowed_values'][1]['vocabulary'] = array(
'#type' => 'select',
'#title' => t('Vocabulary for new terms'),
'#default_value' => isset($field['settings']['allowed_values'][1]['vocabulary']) ? $field['settings']['allowed_values'][1]['vocabulary'] : '',
'#options' => $options,
'#description' => t('New terms form autocompletes will be inserted in this vocabulary.'),
);
$form['field']['settings']['allowed_values'][1]['parent'] = array(
'#type' => 'value',
'#value' => $field['settings']['allowed_values'][1]['parent'],
);
if ($instance['widget']['type'] == 'autocomplete_deluxe_taxonomy') {
// todo: should this setting be added field_info_alter?
$form['field']['settings']['allowed_values'][1]['content_taxonomy_ignore_in_suggestions'] = array(
'#type' => 'checkbox',
'#title' => t('Ignore vocabulary above for suggested terms.'),
'#default_value' => isset($field['settings']['allowed_values'][1]['content_taxonomy_ignore_in_suggestions']) ? $field['settings']['allowed_values'][1]['content_taxonomy_ignore_in_suggestions'] : FALSE,
);
}
}
}