Index: plugins/content_types/node_context/node_terms.inc =================================================================== RCS file: plugins/content_types/node_context/node_terms.inc diff -N plugins/content_types/node_context/node_terms.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ plugins/content_types/node_context/node_terms.inc 19 May 2010 07:00:00 -0000 @@ -0,0 +1,144 @@ + TRUE, + 'title' => t('Node terms'), + 'icon' => 'icon_node.png', + 'description' => t('Taxonomy terms of the referenced node.'), + 'required context' => new ctools_context_required(t('Node'), 'node'), + 'category' => t('Node'), + 'defaults' => array( + 'vid' => 0, + 'link' => TRUE, + 'term_format' => 'ul', + 'term_delimiter' => '', + ), +); + +/** + * Render the node_terms content type. + */ +function ctools_node_terms_content_type_render($subtype, $conf, $panel_args, $context) { + if (empty($context) || empty($context->data)) { + return; + } + + // Get a shortcut to the node. + $node = $context->data; + + if (empty($node->taxonomy)) { + return; + } + + $terms = array(); + foreach ($context->data->taxonomy as $term) { + if (empty($conf['vid']) || $term->vid == $conf['vid']) { + if (empty($conf['link'])) { + $terms[] = check_plain($term->name); + } + else { + $terms[] = l($term->name, taxonomy_term_path($term), array('attributes' => array('rel' => 'tag', 'title' => strip_tags($term->description)))); + } + } + } + + $formatted_terms = ''; + if ($conf['term_format'] == 'ul') { + $formatted_terms = theme('item_list', $terms); + } + elseif ($conf['term_format'] == 'inline-delimited') { + $delimiter = isset($conf['term_delimiter']) ? $conf['term_delimiter'] : ', '; + $formatted_terms = implode($delimiter, $terms); + } + + // Build the content type block. + $block = new stdClass(); + $block->module = 'node_terms'; + $block->delta = $node->nid; + $block->title = $type->title_label; + $block->content = $formatted_terms; + + return $block; +} + +/** + * Returns an edit form for custom type settings. + */ +function ctools_node_terms_content_type_edit_form(&$form, &$form_state) { + ctools_include('dependent'); + + $conf = $form_state['conf']; + + $options = array(); + $options[0] = t('- All vocabularies -'); + foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) { + $options[$vid] = $vocabulary->name; + } + $form['vid'] = array( + '#title' => t('Vocabulary'), + '#type' => 'select', + '#options' => $options, + '#default_value' => $conf['vid'], + '#description' => t('Optionally restrict the terms to a specific vocabulary, or allow terms from all vocabularies.'), + '#prefix' => '