1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Plugin to provide an argument handler for a user id
|
6
|
*/
|
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("Forum: ID"),
|
14
|
// Keyword to use for %substitution.
|
15
|
'keyword' => 'forum',
|
16
|
'description' => t('Creates a forum context from a forum ID argument.'),
|
17
|
'context' => 'advanced_forum_argument_forum_id_context',
|
18
|
'placeholder form' => array(
|
19
|
'#type' => 'textfield',
|
20
|
'#description' => t('Enter the forum ID of a form for this argument'),
|
21
|
),
|
22
|
'settings form' => 'advanced_forum_forum_id_settings_form',
|
23
|
'breadcrumb' => 'advanced_forum_forum_id_breadcrumb',
|
24
|
'default' => array('breadcrumb' => TRUE),
|
25
|
);
|
26
|
|
27
|
/**
|
28
|
* Discover if this argument gives us the user we crave.
|
29
|
*/
|
30
|
function advanced_forum_argument_forum_id_context($arg = NULL, $conf = NULL, $empty = FALSE) {
|
31
|
// If unset it wants a generic, unfilled context.
|
32
|
if ($empty) {
|
33
|
return ctools_context_create_empty('forum');
|
34
|
}
|
35
|
|
36
|
if (!is_numeric($arg)) {
|
37
|
return NULL;
|
38
|
}
|
39
|
|
40
|
if ($arg != 0) {
|
41
|
$term = taxonomy_term_load($arg);
|
42
|
}
|
43
|
|
44
|
if ($arg == 0 || empty($term) || $term->vid != variable_get('forum_nav_vocabulary', 0)) {
|
45
|
$term = taxonomy_vocabulary_load(variable_get('forum_nav_vocabulary', 0));
|
46
|
$term->tid = 0;
|
47
|
}
|
48
|
|
49
|
if (!$term) {
|
50
|
return NULL;
|
51
|
}
|
52
|
|
53
|
return ctools_context_create('forum', $term);
|
54
|
}
|
55
|
|
56
|
/**
|
57
|
* Settings form for the argument.
|
58
|
*/
|
59
|
function advanced_forum_forum_id_settings_form(&$form, &$form_state, $conf) {
|
60
|
$form['settings']['breadcrumb'] = array(
|
61
|
'#title' => t('Inject hierarchy into breadcrumb trail'),
|
62
|
'#type' => 'checkbox',
|
63
|
'#default_value' => !empty($conf['breadcrumb']),
|
64
|
'#description' => t('If checked, forum parents will appear in the breadcrumb trail.'),
|
65
|
);
|
66
|
}
|
67
|
|
68
|
/**
|
69
|
* Inject the breadcrumb trail if necessary.
|
70
|
*/
|
71
|
function advanced_forum_forum_id_breadcrumb($conf, $context) {
|
72
|
if (empty($conf['breadcrumb'])) {
|
73
|
return;
|
74
|
}
|
75
|
|
76
|
$breadcrumb = array();
|
77
|
if (isset($context->data->parents)) {
|
78
|
$parents = array_reverse($context->data->parents);
|
79
|
if (!empty($parents)) {
|
80
|
foreach ($parents as $p) {
|
81
|
if ($p->tid != $context->data->tid) {
|
82
|
$breadcrumb[] = l($p->name, 'forum/' . $p->tid);
|
83
|
}
|
84
|
}
|
85
|
}
|
86
|
}
|
87
|
|
88
|
$breadcrumb = array_merge(drupal_get_breadcrumb(), $breadcrumb);
|
89
|
drupal_set_breadcrumb($breadcrumb);
|
90
|
}
|