1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
c304a780
|
Assos Assos
|
* Plugin to provide a vocabulary context.
|
6 |
85ad3d82
|
Assos Assos
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Plugins are described by creating a $plugin array which will be used
|
10 |
|
|
* by the system that includes this file.
|
11 |
|
|
*/
|
12 |
|
|
$plugin = array(
|
13 |
|
|
'title' => t("Taxonomy vocabulary"),
|
14 |
|
|
'description' => t('A single taxonomy vocabulary object.'),
|
15 |
|
|
'context' => 'ctools_context_create_vocabulary',
|
16 |
|
|
'edit form' => 'ctools_context_vocabulary_settings_form',
|
17 |
|
|
'defaults' => array('vid' => ''),
|
18 |
|
|
'keyword' => 'vocabulary',
|
19 |
|
|
'context name' => 'vocabulary',
|
20 |
|
|
// This context is deprecated and should not be usable in the UI.
|
21 |
|
|
'no ui' => TRUE,
|
22 |
|
|
'no required context ui' => TRUE,
|
23 |
|
|
'superceded by' => 'entity:taxonomy_vocabulary',
|
24 |
|
|
);
|
25 |
|
|
|
26 |
|
|
/**
|
27 |
|
|
* It's important to remember that $conf is optional here, because contexts
|
28 |
|
|
* are not always created from the UI.
|
29 |
|
|
*/
|
30 |
|
|
function ctools_context_create_vocabulary($empty, $data = NULL, $conf = FALSE) {
|
31 |
|
|
$context = new ctools_context('vocabulary');
|
32 |
|
|
$context->plugin = 'vocabulary';
|
33 |
|
|
|
34 |
|
|
if ($empty) {
|
35 |
|
|
return $context;
|
36 |
|
|
}
|
37 |
|
|
|
38 |
|
|
if ($conf && isset($data['vid'])) {
|
39 |
|
|
$data = taxonomy_vocabulary_load($data['vid']);
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
if (!empty($data)) {
|
43 |
|
|
$context->data = $data;
|
44 |
|
|
$context->title = $data->name;
|
45 |
|
|
$context->argument = $data->vid;
|
46 |
|
|
return $context;
|
47 |
|
|
}
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
function ctools_context_vocabulary_settings_form($form, &$form_state) {
|
51 |
|
|
$conf = $form_state['conf'];
|
52 |
|
|
|
53 |
|
|
$options = array();
|
54 |
|
|
foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
|
55 |
|
|
$options[$vid] = $vocabulary->name;
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
$form['vid'] = array(
|
59 |
|
|
'#title' => t('Vocabulary'),
|
60 |
|
|
'#type' => 'select',
|
61 |
|
|
'#options' => $options,
|
62 |
|
|
'#default_value' => $conf['vid'],
|
63 |
|
|
'#description' => t('Select the vocabulary for this form.'),
|
64 |
|
|
);
|
65 |
|
|
|
66 |
|
|
return $form;
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
function ctools_context_vocabulary_settings_form_submit($form, &$form_state) {
|
70 |
|
|
$form_state['conf']['vid'] = $form_state['values']['vid'];
|
71 |
|
|
} |