1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Plugins are described by creating a $plugin array which will be used
|
6
|
* by the system that includes this file.
|
7
|
*/
|
8
|
|
9
|
$plugin = array(
|
10
|
'single' => TRUE,
|
11
|
'title' => t('Term name'),
|
12
|
'icon' => 'icon_term.png',
|
13
|
'description' => t('The name of this taxonomy term.'),
|
14
|
'required context' => new ctools_context_required(t('Term'), array('term', 'taxonomy_term')),
|
15
|
'category' => t('Taxonomy term'),
|
16
|
'defaults' => array(
|
17
|
'link' => TRUE,
|
18
|
'markup' => 'none',
|
19
|
'id' => '',
|
20
|
'class' => '',
|
21
|
),
|
22
|
);
|
23
|
|
24
|
/**
|
25
|
* Render the custom content type.
|
26
|
*/
|
27
|
function ctools_term_name_content_type_render($subtype, $conf, $panel_args, $context) {
|
28
|
if (empty($context) || empty($context->data)) {
|
29
|
return;
|
30
|
}
|
31
|
|
32
|
// Get a shortcut to the term.
|
33
|
$term = $context->data;
|
34
|
|
35
|
// Load the vocabulary.
|
36
|
$vocab = taxonomy_vocabulary_load($term->vid);
|
37
|
|
38
|
// Generate the title.
|
39
|
$content = !empty($conf['link']) ? l($term->name, 'taxonomy/term/' . $term->tid) : check_plain($term->name);
|
40
|
|
41
|
// Build any surrounding markup if so configured.
|
42
|
if (isset($conf['markup']) && $conf['markup'] != 'none') {
|
43
|
$markup = '<' . $conf['markup'];
|
44
|
if (!empty($conf['id'])) {
|
45
|
$markup .= ' id="' . $conf['id'] . '"';
|
46
|
}
|
47
|
if (!empty($conf['class'])) {
|
48
|
$markup .= ' class="' . $conf['class'] . '"';
|
49
|
}
|
50
|
$markup .= '>' . $content . '</' . $conf['markup'] . '>' . "\n";
|
51
|
$content = $markup;
|
52
|
}
|
53
|
|
54
|
// Build the content type block.
|
55
|
$block = new stdClass();
|
56
|
$block->module = 'term_name';
|
57
|
$block->title = t('Name');
|
58
|
$block->content = $content;
|
59
|
$block->delta = $term->tid;
|
60
|
|
61
|
return $block;
|
62
|
}
|
63
|
|
64
|
/**
|
65
|
* Returns an edit form for custom type settings.
|
66
|
*/
|
67
|
function ctools_term_name_content_type_edit_form($form, &$form_state) {
|
68
|
$conf = $form_state['conf'];
|
69
|
|
70
|
$form['markup'] = array(
|
71
|
'#title' => t('Title tag'),
|
72
|
'#type' => 'select',
|
73
|
'#options' => array(
|
74
|
'none' => t('- No tag -'),
|
75
|
'h1' => t('h1'),
|
76
|
'h2' => t('h2'),
|
77
|
'h3' => t('h3'),
|
78
|
'h4' => t('h4'),
|
79
|
'h5' => t('h5'),
|
80
|
'h6' => t('h6'),
|
81
|
'div' => t('div'),
|
82
|
),
|
83
|
'#default_value' => $conf['markup'],
|
84
|
);
|
85
|
|
86
|
$form['id'] = array(
|
87
|
'#title' => t('CSS id to use'),
|
88
|
'#type' => 'textfield',
|
89
|
'#default_value' => $conf['id'],
|
90
|
);
|
91
|
|
92
|
$form['class'] = array(
|
93
|
'#title' => t('CSS class to use'),
|
94
|
'#type' => 'textfield',
|
95
|
'#default_value' => $conf['class'],
|
96
|
);
|
97
|
|
98
|
$form['link'] = array(
|
99
|
'#title' => t('Link to term'),
|
100
|
'#type' => 'checkbox',
|
101
|
'#default_value' => $conf['link'],
|
102
|
'#description' => t('Check here to make the name link to the term page.'),
|
103
|
);
|
104
|
return $form;
|
105
|
}
|
106
|
|
107
|
/**
|
108
|
* Submit handler for the custom type settings form.
|
109
|
*/
|
110
|
function ctools_term_name_content_type_edit_form_submit($form, &$form_state) {
|
111
|
// Copy everything from our defaults.
|
112
|
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
|
113
|
$form_state['conf'][$key] = $form_state['values'][$key];
|
114
|
}
|
115
|
}
|
116
|
|
117
|
/**
|
118
|
* Returns the administrative title for a type.
|
119
|
*/
|
120
|
function ctools_term_name_content_type_admin_title($subtype, $conf, $context) {
|
121
|
return t('"@s" name', array('@s' => $context->identifier));
|
122
|
}
|