Newer
Older
Earl Miles
committed
<?php
// $Id$
/**
* @file arguments/vid.inc
*
* Plugin to provide an argument handler for a vocabulary id
*/
function panels_vid_panels_arguments() {
$args['vid'] = array(
'title' => t("Vocabulary ID"),
// keyword to use for %substitution
'keyword' => 'vocabulary',
'description' => t('Loads a vocabulary object from the argument.'),
'context' => 'panels_vid_context',
'settings form' => 'panels_vid_settings_form',
'settings form submit' => 'panels_vid_settings_form_submit',
'displays' => 'panels_vid_displays',
'choose display' => 'panels_vid_choose_display',
);
return $args;
}
/**
* Discover if this argument gives us the vocabulary we crave.
*/
function panels_vid_context($arg = NULL, $conf = NULL, $empty = FALSE) {
// If unset it wants a generic, unfilled context.
if ($empty) {
return panels_context_create_empty('vocabulary');
}
if (!is_numeric($arg)) {
Earl Miles
committed
}
$vocabulary = taxonomy_get_vocabulary($arg);
if (!$vocabulary) {
Earl Miles
committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
}
return panels_context_create('vocabulary', $vocabulary);
}
/**
* Settings form for the argument
*/
function panels_vid_settings_form($conf) {
$options = array();
foreach (taxonomy_get_vocabularies() as $vid => $voc) {
$options[$vid] = $voc->name;
}
$form['displays'] = array(
'#title' => t('Own display'),
'#type' => 'checkboxes',
'#options' => $options,
'#default_value' => $conf['displays'],
'#description' => t('Each checked vocabulary will get its own special display to layout its content.'),
'#prefix' => '<div class="clear-block">',
'#suffix' => '</div>',
);
return $form;
}
/**
* There appears to be a bit of a bug with the way we're handling forms; it causes
* 'checkboxes' to get invalid values added to them when empty. This takes care
* of that.
*/
function panels_vid_settings_form_submit(&$values) {
$vocs = taxonomy_get_vocabularies();
if (!empty($values['displays'])) {
foreach ($values['displays'] as $vid => $value) {
if (empty($vocs[$vid])) {
unset($values['displays'][$vid]);
}
}
}
}
/**
* What additional displays does this argument provide?
*/
function panels_vid_displays($conf, $id) {
$displays = array();
if (is_array($conf['displays'])) {
$options = array();
foreach (taxonomy_get_vocabularies() as $vid => $info) {
$options[$vid] = $info->name;
}
foreach (array_keys(array_filter($conf['displays'])) as $vid) {
$displays[$vid] = array(
'title' => t('vocabulary ID @id @type', array('@id' => $id, '@type' => $options[$vid])),
// Tell it to base the template for this display off of the default.
'default' => 'default',
'context' => 'vocabulary',
);
}
}
return $displays;
}
/**
* Based upon the settings and the context, choose which display to use.
*/
function panels_vid_choose_display($conf, $context) {
if (empty($context->data)) {
return;
}
if (!empty($conf['displays'][$context->data->vid])) {
return $context->data->vid;
}
// Empty return says to use the default display.
return;
}