1 taxonomy.module | taxonomy_field_widget_form_alter(&$element, &$form_state, $context) |
Implements hook_field_widget_form_alter().
File
- core/
modules/ taxonomy/ taxonomy.module, line 1859 - Enables the organization of content into categories.
Code
function taxonomy_field_widget_form_alter(&$element, &$form_state, $context) {
$field = $context['field'];
$widget_type = $context['instance']['widget']['type'];
if ($field['type'] == 'taxonomy_term_reference' && in_array($widget_type, array('options_buttons', 'options_select'))) {
foreach ($field['settings']['allowed_values'] as $tree) {
if ($vocabulary = taxonomy_vocabulary_load($tree['vocabulary'])) {
if ($terms = taxonomy_get_tree($vocabulary->machine_name, $tree['parent'])) {
foreach ($terms as $term) {
if (isset($element['#options'][$term->tid])) {
$element[$term->tid] = array('#indentation' => $term->depth);
}
}
}
}
}
}
}