Note: Requires content.module.'); } } /** * Implementation of hook_widget_info(). */ function content_taxonomy_activeselect_widget_info() { return array( 'content_taxonomy_activeselect' => array( 'label' => 'ActiveSelect', 'field types' => array('content_taxonomy'), ), ); return $items; } /** * Implementation of hook_widget_settings */ function content_taxonomy_activeselect_widget_settings($op, $widget) { switch ($op) { case 'form': $form = array(); $options_term = array(); $options_term[0] = '---'; foreach (taxonomy_get_vocabularies() as $voc) { foreach (taxonomy_get_tree($voc->vid) as $term) { $options_term[$voc->name][$term->tid] = $term->name; } } $form['activeselect'] = array( '#type' => 'fieldset', '#title' => t('Activeselect'), '#collapsible' => TRUE, '#description' => t(''), ); $form['activeselect']['label_children'] = array( '#type' => 'textfield', '#title' => t('Label for second bar'), '#default_value' => isset($widget['label_children']) ? $widget['label_children'] : '', '#size' => 60, ); $form['activeselect']['grandchildren'] = array( '#title' => t('Third bar'), '#type' => 'checkbox', '#default_value' => isset($widget['grandchildren']) ? $widget['grandchildren'] : 0, ); $form['activeselect']['label_grandchildren'] = array( '#type' => 'textfield', '#title' => t('Label for third bar'), '#default_value' => isset($widget['label_grandchildren']) ? $widget['label_grandchildren'] : '', '#size' => 60, ); return $form; case 'save': return array('grandchildren', 'label_children', 'label_grandchildren'); } } /** * Implementation of hook_widget(). */ function content_taxonomy_activeselect_widget($op, &$node, $field, &$node_field) { $vid = $field['vid']; $tid = $field['tid']; switch ($op) { case 'prepare form values': if (!$node_field) { $node_field['default_tid'] = $_POST['edit'][$field['field_name']]['tid']; $node_field['default_children'] = $_POST['edit'][$field['field_name']]['children']; $node_field['default_grandchildren'] = $_POST['edit'][$field['field_name']]['grandchildren']; } break; case 'form': $form = array(); $children = taxonomy_get_children($tid,$vid); foreach ($children as $term) { $options_terms[$term->tid] = $term->name; } if (is_array($node_field['default_children'])) { $default_children = implode(',', $node_field['default_children']); } else { $default_children = ""; } $form[$field['field_name']] = array('#tree' => TRUE); $form[$field['field_name']]['tid'] = array( '#title' => $field['widget']['label'], '#type' => 'activeselect', '#activeselect_path' => 'content_taxonomy/activeselect', '#activeselect_targets' => $field['field_name'] .'-children', '#activeselect_extra' => 'term,'. FALSE .','. $field['vid'] .','. $field['field_name'] .'-children#'. $default_children, '#default_value' => isset($node_field['default_tid']) ? array_values($node_field['default_tid']) : array(), '#options' => $options_terms, '#required' => $field['required'], '#DANGEROUS_SKIP_CHECK' => TRUE, ); $form[$field['field_name']]['children'] = array( '#title' => $field['widget']['label_children'], '#options' => array(), '#multiple' => FALSE, '#required' => $field['required'], '#DANGEROUS_SKIP_CHECK' => TRUE, ); if (!$field['widget']['grandchildren']) { $form[$field['field_name']]['children']['#type'] = 'select'; } else { if (is_array($node_field['default_grandchildren'])) { $default_grandchildren = implode(',', $node_field['default_grandchildren']); } else { $default_grandchildren = ""; } $form[$field['field_name']]['children']['#type'] = 'activeselect'; $form[$field['field_name']]['children']['#activeselect_path'] = 'content_taxonomy/activeselect'; $form[$field['field_name']]['children']['#activeselect_targets'] = $field['field_name']. '-grandchildren'; $form[$field['field_name']]['children']['#activeselect_extra'] = 'term,'. FALSE .','. $field['vid'] .','. $field['field_name']. '-grandchildren#'. $default_grandchildren; $form[$field['field_name']]['grandchildren'] = array( '#title' => $field['widget']['label_grandchildren'], '#type' => 'select', '#options' => array(), '#required' => $field['required'], '#DANGEROUS_SKIP_CHECK' => TRUE, ); } return $form; case 'process form values': if (is_array($node_field['tid'])) { foreach ($node_field['tid'] as $tid) { $node_field['tids'][] = $tid; } } elseif (isset($node_field['tid'])) { $node_field['tids'][] = $node_field['tid']; } unset($node_field['tid']); if (is_array($node_field['children'])) { foreach ($node_field['children'] as $tid) { $node_field['tids'][] = $tid; } } elseif (isset($node_field['children'])) { $node_field['tids'][] = $node_field['children']; } unset($node_field['children']); if (is_array($node_field['grandchildren'])) { foreach ($node_field['grandchildren'] as $tid) { $node_field['tids'][] = $tid; } } elseif (isset($node_field['grandchildren'])) { $node_field['tids'][] = $node_field['grandchildren']; } unset($node_field['grandchildren']); } } /** * Implementation of hook_menu */ function content_taxonomy_activeselect_menu($may_cache) { $access = user_access('access content'); $items = array(); if (!$may_cache) { $items[] = array( 'path' => 'content_taxonomy/activeselect', 'callback' => 'content_taxonomy_activeselect', 'access' => $access, 'type' => MENU_CALLBACK); } return $items; } /** * return depending values (--> ajax) see activeselect */ function content_taxonomy_activeselect($source, $targets, $string, $extra = NULL) { if (empty($source) || empty($targets) || empty($string)) { exit(); } $targets = explode(',', $targets); $extras = explode(',',$extra); $type = $extras[0]; $multiple = $extras[1]; $default_vid = $extras[2]; for ($i=2; $i $value) { if ($type == 'voc') { $terms = taxonomy_get_tree($id); $options[0]['value'] = '< whole vocabulary >'; } else { $terms = taxonomy_get_children($id); $options[0]['value'] = '---'; } foreach ($terms as $term) { $options[$term->tid]['value'] = $term->name; if (is_array($default_tids[$target]) && in_array($term->tid,$default_tids[$target])) $options[$term->tid]['selected'] = TRUE; } } $multiple = $multiple; $output[$target] = array('options' => $options, 'multiple' => $multiple); } activeselect_set_header_nocache(); print drupal_to_js($output); exit(); } /** * adding of terms when node is loaded (called by content_taxonomy) */ function content_taxonomy_activeselect_field_load($op, &$node, $field, &$node_field, &$additions, $teaser, $page) { $default_terms = content_taxonomy_terms_by_field($node->nid, $field['vid'], $field['tid']); $additions[$field['field_name']]['default_tid'] = array_keys($default_terms); $default_terms = array_values($default_terms); $children_terms = content_taxonomy_terms_by_field($node->nid, $field['vid'], $default_terms[0]->tid); if (is_array($children_terms)) { foreach ($children_terms as $term) { $additions[$field['field_name']]['tid'][$term->tid] = $term; } $additions[$field['field_name']]['default_children'] = array(); $additions[$field['field_name']]['default_children'] = array_keys($children_terms); $children_terms = array_values($children_terms); if ($field['widget']['grandchildren']) { $grandchildren_terms = content_taxonomy_terms_by_field($node->nid, $field['vid'], $children_terms[0]->tid); if (is_array($grandchildren_terms)) { foreach ($grandchildrenchildren_terms as $term) { $additions[$field['field_name']]['tid'][$term->tid] = $term; } $additions[$field['field_name']]['default_grandchildren'] = array(); $additions[$field['field_name']]['default_grandchildren'] = array_keys($grandchildren_terms); } } } } ?>