array('element' => NULL)); foreach (array('text', 'link') as $type) { foreach (array('inline', 'block') as $style) { $items['content_taxonomy_term_list_formatter_'. $type .'__'. $style] = array( 'arguments' => array('element' => NULL), 'function' => 'theme_content_taxonomy_term_list_formatter_default', ); } } return $items; } /** * Implementation of hook_field_info(). */ function content_taxonomy_term_list_field_info() { return array( 'content_taxonomy_term_list' => array( 'label' => t('Content Taxonomy Term List'), 'description' => t('Represents a read-only field for terms'), 'callbacks' => array( 'tables' => CONTENT_CALLBACK_DEFAULT, 'arguments' => CONTENT_CALLBACK_DEFAULT, ), ), ); } /** * Implementation of hook_field_settings(). */ function content_taxonomy_term_list_field_settings($op, $field) { switch ($op) { case 'form': $form = array(); $form['multiple'] = array('#type' => 'value', '#value' => 1); $form['required'] = array('#type' => 'value', '#value' => 0); return $form; case 'save' : return array(); case 'database columns' : return array(); case 'views data' : return array(); } } /** * Implementation of hook_field(). */ function content_taxonomy_term_list_field($op, &$node, $field, &$items, $teaser, $page) { switch ($op) { case 'insert' : if (empty($items['0'])) { $items = array(); $node->{$field['field_name']} = array(); } break; case 'load': $vids = array_filter($field['widget']['vids']); $values = array(); $args = array_merge(array($node->nid), $vids); $result = db_query('SELECT td.* FROM {term_node} tn INNER JOIN {term_data} td ON td.tid = tn.tid WHERE tn.nid = %d AND td.vid IN ('. db_placeholders($vids) .')', $args); while ($term = db_fetch_array($result)) { $values[] = $term; } return array($field['field_name'] => $values); } } /** * Implementation of hook_widget_info(). */ function content_taxonomy_term_list_widget_info() { return array( 'content_taxonomy_term_list_readonly' => array( 'label' => t('Term List (read only)'), 'field types' => array('content_taxonomy_term_list'), 'multiple values' => CONTENT_HANDLE_MODULE, 'callbacks' => array( 'default value' => CONTENT_CALLBACK_DEFAULT, ), ), ); } /** * Implementation of hook_widget_settings(). */ function content_taxonomy_term_list_widget_settings($op, $widget) { switch ($op) { case 'form': $form = array(); $options = array(); $vocabs = taxonomy_get_vocabularies(); foreach ($vocabs as $v) { $options[$v->vid] = $v->name; } $form['vids'] = array( '#title' => t('Which vocabularies should this field display?'), '#type' => 'checkboxes', '#options' => $options, '#default_value' => isset($widget['vids']) ? $widget['vids'] : array(), ); return $form; case 'save' : return array('vids'); } } /** * Implementation of hook_field_formatter_info(). */ function content_taxonomy_term_list_field_formatter_info() { $items = array(); foreach (array('text', 'link') as $type) { foreach (array('inline', 'block') as $style) { $items[$type .'__'. $style] = array( 'label' => t('As !style !type', array('!style' => $style, '!type' => $type)), 'field types' => array('content_taxonomy_term_list'), 'multiple values' => CONTENT_HANDLE_MODULE, ); } } return $items; } /** * Theme function for 'default' text field formatter. */ function theme_content_taxonomy_term_list_formatter_default($element) { list($type, $style) = explode('__', $element['#formatter']); // Define our wrapper HTML element depending on formatter style switch ($style) { case 'inline' : $wrapper = 'span'; break; case 'block' : $wrapper = 'div'; break; } // Generate the values $values = array(); foreach (element_children($element) as $key) { // Grab the term and make an object $term = (object)$element[$key]['#item']; // Depending on type (text or link), create a value switch ($type) { case 'link' : $value = l($term->name, taxonomy_term_path($term)); break; case 'text' : $value = check_plain($term->name); break; } // Add it to our values, wrapper in the appropriate wrapper $values[] = "<{$wrapper}>{$value}"; } // Reset the value string - we need this now for the return value $value = ''; // If the style is inline (not block), then we can make this a fancy "a, b and c" type list. if ($style == 'inline') { // Only need to do this if its greater than 1 item. if (count($values) > 1) { $last = array_pop($values); $value = t('!firsts, !last', array('!firsts' => implode(', ', $values), '!last' => $last)); } else { $value = array_pop($values); } } else { $value = implode("\n", $values); } return $value; } /** * Implementation of hook_content_is_empty(). */ function content_taxonomy_term_list_content_is_empty($item, $field) { return empty($item); } /** * Implementation of hook_taxonomy(). */ function content_taxonomy_term_list_taxonomy($op, $type, $array = NULL) { switch ($op) { case 'delete' : case 'update' : cache_clear_all('content:', 'cache_content', TRUE); break; } }