4 * Plugins are described by creating a $plugin array which will be used
5 * by the system that includes this file.
9 'title' => t('Node terms'),
10 'icon' => 'icon_node.png',
11 'description' => t('Taxonomy terms of the referenced node.'),
12 'required context' => new ctools_context_required(t('Node'), 'node'),
13 'category' => t('Node'),
16 'term_format' => 'term-links',
18 'term_delimiter' => ', ',
23 * Render the node_terms content type.
25 function ctools_node_terms_content_type_render($subtype, $conf, $panel_args, $context) {
26 if (empty($context) || empty($context->data)) {
30 // Get a shortcut to the node.
31 $node = $context->data;
33 // Load all terms for this node from all vocabularies
34 $query = db_select('taxonomy_index', 't');
37 ->condition('t.nid', $node->nid)
41 foreach ($result AS $term) {
45 // Get the real term objects
46 $term_objects = taxonomy_term_load_multiple($tids);
50 if (empty($conf['vid'])) {
52 foreach ($term_objects AS $term) {
53 $terms['taxonomy_term_' . $term->tid] = array(
54 'title' => check_plain($term->name),
55 'href' => 'taxonomy/term/' . $term->tid,
56 'attributes' => array('rel' => 'tag', 'title' => strip_tags($term->description))
61 // They want something special and custom, we'll have to do this ourselves.
62 foreach ($term_objects as $term) {
63 if ($term->vid == $conf['vid']) {
64 if ($conf['term_format'] == 'term-links') {
65 $terms['taxonomy_term_' . $term->tid] = array(
66 'title' => $term->name,
67 'href' => 'taxonomy/term/' . $term->tid,
68 'attributes' => array('rel' => 'tag', 'title' => strip_tags($term->description)),
71 elseif (empty($conf['link'])) {
72 $terms[] = check_plain($term->name);
75 $terms[] = l($term->name, 'taxonomy/term/' . $term->tid, array('attributes' => array('rel' => 'tag', 'title' => strip_tags($term->description))));
81 $formatted_terms = '';
82 switch ($conf['term_format']) {
84 drupal_alter('link', $terms, $node);
85 $formatted_terms = theme('links', array('links' => $terms));
89 $formatted_terms = theme('item_list', array('items' => $terms));
92 case 'inline-delimited':
93 $delimiter = isset($conf['term_delimiter']) ? $conf['term_delimiter'] : ', ';
94 $processed_terms = array();
95 foreach ($terms as $key => $term) {
96 if (is_string($term)) {
97 $processed_terms[$key] = $term;
100 $terms[$key] = l($term['title'], $term['href'], $term);
104 $formatted_terms = implode($delimiter, $processed_terms);
108 // Build the content type block.
109 $block = new stdClass();
110 $block->module = 'node_terms';
111 $block->delta = $node->nid;
112 $block->title = t('Terms');
113 $block->content = $formatted_terms;
119 * Returns an edit form for node terms display settings.
121 * The first question is if they want to display all terms or restrict it to a
122 * specific taxonomy vocabulary.
124 * Then, they're presented with a set of radios to find out how they want the
125 * terms formatted, which can be either be via theme('links'), a regular item
126 * list (ul), or inline with a delimiter. Depending on which radio they
127 * choose, some other settings might appear. If they're doing either the ul or
128 * inline, we ask if they want the terms to appear as links or not. If they
129 * want it inline, we ask what delimiter they want to use.
131 function ctools_node_terms_content_type_edit_form($form, &$form_state) {
132 ctools_include('dependent');
134 $conf = $form_state['conf'];
137 $options[0] = t('- All vocabularies -');
138 foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
139 $options[$vid] = $vocabulary->name;
141 $form['vid'] = array(
142 '#title' => t('Vocabulary'),
144 '#options' => $options,
145 '#default_value' => $conf['vid'],
146 '#description' => t('Optionally restrict the terms to a specific vocabulary, or allow terms from all vocabularies.'),
147 '#prefix' => '<div class="clearfix">',
148 '#suffix' => '</div>',
151 $form['term_format'] = array(
153 '#title' => t('Term formatting'),
155 'term-links' => t("Taxonomy links (uses theme('links'))"),
156 'ul' => t('Unordered list'),
157 'inline-delimited' => t('Inline, delimited'),
159 '#default_value' => $conf['term_format'],
160 '#prefix' => '<div class="clearfix">',
161 '#suffix' => '</div>',
164 $form['link'] = array(
165 '#title' => t('Link to terms'),
166 '#type' => 'checkbox',
167 '#default_value' => $conf['link'],
168 '#description' => t('Check here to make the terms link to the term paths.'),
169 '#dependency' => array('radio:term_format' => array('inline-delimited', 'ul')),
170 '#prefix' => '<div class="clearfix">',
171 '#suffix' => '</div>',
174 $form['term_delimiter'] = array(
175 '#type' => 'textfield',
176 '#title' => t('Term delimiter'),
177 '#default_value' => $conf['term_delimiter'],
179 '#dependency' => array('radio:term_format' => array('inline-delimited')),
185 * Submit handler for the custom type settings form.
187 function ctools_node_terms_content_type_edit_form_submit($form, &$form_state) {
188 // Copy everything from our defaults.
189 foreach (array_keys($form_state['plugin']['defaults']) as $key) {
190 $form_state['conf'][$key] = $form_state['values'][$key];
195 * Returns the administrative title for a type.
197 function ctools_node_terms_content_type_admin_title($subtype, $conf, $context) {
198 $placeholders['@s'] = $context->identifier;
199 if (!empty($conf['vid'])) {
200 $vocabulary = taxonomy_vocabulary_load($conf['vid']);
201 $placeholders['@vocabulary'] = $vocabulary->name;
202 return t('"@s" terms from @vocabulary', $placeholders);
204 return t('"@s" terms', $placeholders);