Newer
Older
Earl Miles
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
124
125
126
127
128
129
130
<?php
// $Id$
/**
* @file
* Handle the 'term view' override task.
*
* This plugin overrides term/%term and reroutes it to the delegator, where
* a list of tasks can be used to service this request based upon criteria
* supplied by access plugins.
*/
/**
* Specialized implementation of hook_delegator_tasks(). See api-task.html for
* more information.
*/
function delegator_term_view_delegator_tasks() {
return array(
'term_view' => array(
// This is a 'page' task and will fall under the page admin UI
'task type' => 'page',
'title' => t('Taxonomy term view'),
'description' => t('Control what handles the job of displaying a term at taxonomy/term/%term.'),
'admin title' => 'Taxonomy term view', // translated by menu system
'admin description' => 'Overrides for the built in taxonomy term handler at <em>taxonomy/term/%term</em>.',
'admin path' => 'taxonomy/term/%term',
// Menu hooks so that we can alter the term/%term menu entry to point to us.
'hook menu' => 'delegator_term_view_menu',
'hook menu alter' => 'delegator_term_view_menu_alter',
// This is task uses 'context' handlers and must implement these to give the
// handler data it needs.
'handler type' => 'context',
'get arguments' => 'delegator_term_view_get_arguments',
'get context placeholders' => 'delegator_term_view_get_contexts',
// Allow additional operations
'operations' => array(
array(
'title' => t('Task handlers'),
'href' => "admin/build/delegator/term_view",
),
/*
array(
'title' => t('Settings'),
'href' => "admin/build/delegator/term_view/settings",
),
*/
),
),
);
}
/**
* Callback defined by delegator_term_view_delegator_tasks().
*
* Alter the term view input so that term view comes to us rather than the
* normal term view process.
*/
function delegator_term_view_menu_alter(&$items, $task) {
// Override the term view handler for our purpose.
$items['taxonomy/term/%']['page callback'] = 'delegator_term_view';
$items['taxonomy/term/%']['file path'] = $task['path'];
$items['taxonomy/term/%']['file'] = $task['file'];
}
/**
* Entry point for our overridden term view.
*
* This function asks its assigned handlers who, if anyone, would like
* to run with it. If no one does, it passes through to Drupal core's
* term view, which is term_page_view().
*/
function delegator_term_view($terms, $depth = 0, $op = 'page') {
// While we ordinarily should never actually get feeds through here,
// just in case
if ($op != 'feed') {
// Load my task plugin
$task = delegator_get_task('term_view');
// Load the term into a context.
ctools_include('context');
ctools_include('context-task-handler');
$contexts = ctools_context_handler_get_task_contexts($task, '', array($terms, $depth));
$output = ctools_context_handler_render($task, '', $contexts);
if ($output !== FALSE) {
return $output;
}
}
// Otherwise, fall back.
module_load_include('inc', 'taxonomy', 'taxonomy.pages');
return taxonomy_term_page($terms, $depth, $op);
}
/**
* Callback to get arguments provided by this task handler.
*
* Since this is the term view and there is no UI on the arguments, we
* create dummy arguments that contain the needed data.
*/
function delegator_term_view_get_arguments($task, $subtask_id) {
return array(
array(
'keyword' => 'term',
'identifier' => t('Term(s) being viewed'),
'id' => 0,
'name' => 'terms',
'settings' => array(),
),
array(
'keyword' => 'depth',
'identifier' => t('Depth'),
'id' => 0,
'name' => 'string',
'settings' => array(),
),
);
}
/**
* Callback to get context placeholders provided by this handler.
*/
function delegator_term_view_get_contexts($task, $subtask_id) {
return ctools_context_get_placeholders_from_argument(delegator_term_view_get_arguments($task, $subtask_id));
}