1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* Plugins are described by creating a $plugin array which will be used
|
5
|
* by the system that includes this file.
|
6
|
*/
|
7
|
$plugin = array(
|
8
|
'single' => TRUE,
|
9
|
'title' => t('List of related terms'),
|
10
|
'icon' => 'icon_term.png',
|
11
|
'description' => t('Terms related to an existing term; may be child, siblings or top level.'),
|
12
|
'required context' => new ctools_context_required(t('Term'), array('term', 'taxonomy_term')),
|
13
|
'category' => t('Taxonomy term'),
|
14
|
'defaults' => array('title' => '', 'type' => 'child', 'list_type' => 'ul', 'path' => 'taxonomy/term'),
|
15
|
);
|
16
|
|
17
|
function ctools_term_list_content_type_render($subtype, $conf, $panel_args, $context) {
|
18
|
$term = isset($context->data) ? clone($context->data) : NULL;
|
19
|
$block = new stdClass();
|
20
|
$block->module = 'term-list';
|
21
|
$path = empty($conf['path']) ? 'taxonomy/term/%tid' : $conf['path'];
|
22
|
if (strpos($path, '%tid') === FALSE) {
|
23
|
if (substr($path, -1) != '/') {
|
24
|
$path .= '/';
|
25
|
}
|
26
|
$path .= '%tid';
|
27
|
}
|
28
|
|
29
|
$options = ctools_admin_term_list_options();
|
30
|
$skip = array();
|
31
|
|
32
|
if ($term) {
|
33
|
$block->title = $options[$conf['type']];
|
34
|
$block->delta = $conf['type'];
|
35
|
switch ($conf['type']) {
|
36
|
case 'related':
|
37
|
// FIXME this no longer exists, must be done with Field API
|
38
|
// $terms = taxonomy_get_related($term->tid);
|
39
|
break;
|
40
|
|
41
|
case 'child':
|
42
|
default:
|
43
|
$terms = taxonomy_get_children($term->tid);
|
44
|
break;
|
45
|
|
46
|
case 'top':
|
47
|
$terms = taxonomy_get_tree($term->vid, 0, 1);
|
48
|
break;
|
49
|
|
50
|
case 'parent':
|
51
|
$terms = taxonomy_get_parents($term->tid);
|
52
|
$block->title = count($terms) == 1 ? t('Parent term') : t('Parent terms');
|
53
|
break;
|
54
|
|
55
|
case 'sibling':
|
56
|
$parent = db_query('SELECT parent FROM {taxonomy_term_hierarchy} WHERE tid = :tid', array(':tid' => $term->tid))->fetchField();
|
57
|
if ($parent) {
|
58
|
$terms = taxonomy_get_children($parent, $term->vid);
|
59
|
}
|
60
|
else {
|
61
|
$terms = taxonomy_get_tree($term->vid, 0, 1);
|
62
|
}
|
63
|
|
64
|
$skip[$term->tid] = $term->tid;
|
65
|
break;
|
66
|
|
67
|
case 'synonyms':
|
68
|
// FIXME this no longer exists, must be done with Field API
|
69
|
// $terms = taxonomy_get_synonyms($term->tid);
|
70
|
break;
|
71
|
}
|
72
|
|
73
|
if (!empty($terms)) {
|
74
|
foreach ($terms as $related) {
|
75
|
if (empty($skip[$related->tid])) {
|
76
|
$items[] = l($related->name, str_replace('%tid', $related->tid, $path), array('rel' => 'tag', 'title' => strip_tags($related->description)));
|
77
|
}
|
78
|
}
|
79
|
|
80
|
if (!empty($items)) {
|
81
|
$block->content = theme('item_list', array('items' => $items, 'type' => $conf['list_type']));
|
82
|
}
|
83
|
}
|
84
|
}
|
85
|
else {
|
86
|
$block->content = t('Term description goes here.');
|
87
|
$block->delta = 'unknown';
|
88
|
}
|
89
|
|
90
|
return $block;
|
91
|
}
|
92
|
|
93
|
function ctools_admin_term_list_options() {
|
94
|
return array(
|
95
|
'child' => t('Child terms'),
|
96
|
'related' => t('Related terms (does not work in D7)'),
|
97
|
'sibling' => t('Sibling terms'),
|
98
|
'top' => t('Top level terms'),
|
99
|
'synonyms' => t('Term synonyms (does not work in D7)'),
|
100
|
'parent' => t('Parent term(s)'),
|
101
|
);
|
102
|
}
|
103
|
|
104
|
/**
|
105
|
* Returns an edit form for the custom type.
|
106
|
*/
|
107
|
function ctools_term_list_content_type_edit_form($form, &$form_state) {
|
108
|
$conf = $form_state['conf'];
|
109
|
|
110
|
$form['type'] = array(
|
111
|
'#type' => 'radios',
|
112
|
'#title' => t('Which terms'),
|
113
|
'#options' => ctools_admin_term_list_options(),
|
114
|
'#default_value' => $conf['type'],
|
115
|
'#prefix' => '<div class="clearfix no-float">',
|
116
|
'#suffix' => '</div>',
|
117
|
);
|
118
|
|
119
|
$form['list_type'] = array(
|
120
|
'#type' => 'select',
|
121
|
'#title' => t('List type'),
|
122
|
'#options' => array('ul' => t('Unordered'), 'ol' => t('Ordered')),
|
123
|
'#default_value' => $conf['list_type'],
|
124
|
);
|
125
|
|
126
|
$form['path'] = array(
|
127
|
'#type' => 'textfield',
|
128
|
'#title' => t('Path'),
|
129
|
'#default_value' => empty($conf['path']) ? 'taxonomy/term/%tid' : $conf['path'],
|
130
|
'#description' => t('The path to use for the terms. You may use %tid to place the term id as part of the path; if let off, it will be appended to the end.'),
|
131
|
);
|
132
|
return $form;
|
133
|
}
|
134
|
|
135
|
function ctools_term_list_content_type_admin_title($subtype, $conf, $context) {
|
136
|
$options = ctools_admin_term_list_options();
|
137
|
return t('"@s" @type', array('@s' => $context->identifier, '@type' => drupal_strtolower($options[$conf['type']])));
|
138
|
}
|
139
|
|
140
|
function ctools_term_list_content_type_edit_form_submit($form, &$form_state) {
|
141
|
// Copy everything from our defaults.
|
142
|
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
|
143
|
$form_state['conf'][$key] = $form_state['values'][$key];
|
144
|
}
|
145
|
}
|
146
|
|