Projet

Général

Profil

Paste
Télécharger (5,75 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / advanced_forum / plugins / tasks / forum.inc @ 651307cd

1 85ad3d82 Assos Assos
<?php
2 13c3c9b4 Assos Assos
/**
3
 * @file
4
 * Plugin for tasks.
5
 */
6 85ad3d82 Assos Assos
7 13c3c9b4 Assos Assos
/**
8
 * Page manager tasks.
9
 */
10 85ad3d82 Assos Assos
function advanced_forum_forum_page_manager_tasks() {
11
  return array(
12 13c3c9b4 Assos Assos
    // This is a 'page' task and will fall under the page admin UI.
13 85ad3d82 Assos Assos
    'task type' => 'page',
14
    'title' => t('Forum page'),
15
    'admin title' => t('Forum page'),
16
    'admin description' => t('When enabled, this overrides the default Drupal behavior for displaying forum listings at <em>forum</em> and <em>forum/%forum</em>. If you add variants, you may use selection criteria such as roles or user access to provide different views of the forums. If no variant is selected, the normal advanced forum view will be selected.'),
17
    'admin path' => 'forum/%advanced_forum_forum',
18
    'hook menu' => 'advanced_forum_forum_menu',
19
    'hook menu alter' => 'advanced_forum_forum_menu_alter',
20
    // This is task uses 'context' handlers and must implement these to give the
21
    // handler data it needs.
22 13c3c9b4 Assos Assos
    // Handler type -- misnamed.
23
    'handler type' => 'context',
24 85ad3d82 Assos Assos
    'get arguments' => 'advanced_forum_forum_get_arguments',
25
    'get context placeholders' => 'advanced_forum_forum_get_contexts',
26
    // Allow this to be enabled or disabled:
27
    'disabled' => variable_get('advanced_forum_forum_disabled', TRUE),
28
    'enable callback' => 'advanced_forum_forum_enable',
29
    'access callback' => 'advanced_forum_forum_access_check',
30 13c3c9b4 Assos Assos
    // Allow additional operations.
31 85ad3d82 Assos Assos
    'operations' => array(
32
      'settings' => array(
33
        'title' => t('Settings'),
34
        'description' => t('Edit name, path and other basic settings for the page.'),
35
        'form' => 'advanced_forum_forum_page_settings',
36
      ),
37
    ),
38
    // Even though we don't have subtasks, this allows us to save our settings.
39
    'save subtask callback' => 'advanced_forum_forum_page_save',
40
  );
41
}
42
43
/**
44
 * Callback defined by advanced_forum_forum_page_manager_tasks().
45
 *
46
 * Alter the user view input so that user view comes to us rather than the
47
 * normal user view process.
48
 */
49
function advanced_forum_forum_menu_alter(&$items, $task) {
50
  if (variable_get('advanced_forum_forum_disabled')) {
51
    return;
52
  }
53 13c3c9b4 Assos Assos
54 85ad3d82 Assos Assos
  $items['forum']['page callback'] = 'advanced_forum_forum_page';
55
  $items['forum']['file path'] = $task['path'];
56
  $items['forum']['file'] = $task['file'];
57
58 13c3c9b4 Assos Assos
  // Take over forum/%advanced_forum_forum page.
59 85ad3d82 Assos Assos
  $items['forum/%advanced_forum_forum']['page callback'] = 'advanced_forum_forum_page';
60
  $items['forum/%advanced_forum_forum']['file path'] = $task['path'];
61
  $items['forum/%advanced_forum_forum']['file'] = $task['file'];
62
}
63
64
/**
65
 * Entry point for our overridden user view.
66
 *
67
 * This function asks its assigned handlers who, if anyone, would like
68
 * to run with it. If no one does, it passes through to advanced_forum_page().
69
 */
70
function advanced_forum_forum_page($forum_term = NULL) {
71
  if (!isset($forum_term)) {
72
    // On the main page, display all the top-level forums.
73
    $forum_term = advanced_forum_forum_load(0);
74
  }
75
76 13c3c9b4 Assos Assos
  // Set tid for <root> container.
77 85ad3d82 Assos Assos
  if (!isset($forum_term->tid)) {
78
    $forum_term->tid = 0;
79
  }
80
81
  // Load my task plugin:
82
  $task = page_manager_get_task('forum');
83
84
  // Load the account into a context.
85
  ctools_include('context');
86
  ctools_include('context-task-handler');
87
  $contexts = ctools_context_handler_get_task_contexts($task, '', array($forum_term->tid));
88
89
  $output = ctools_context_handler_render($task, '', $contexts, array($forum_term->tid));
90
  if ($output === FALSE) {
91
    $output = advanced_forum_page($forum_term);
92
  }
93
94
  return $output;
95
}
96
97
/**
98
 * Callback to get arguments provided by this task handler.
99
 *
100
 * Since this is the node view and there is no UI on the arguments, we
101
 * create dummy arguments that contain the needed data.
102
 */
103
function advanced_forum_forum_get_arguments($task, $subtask_id) {
104
  return array(
105
    array(
106
      'keyword' => 'forum',
107
      'identifier' => t('Forum'),
108
      'id' => 1,
109
      'name' => 'forum_id',
110
      'settings' => array('breadcrumb' => variable_get('advanced_forum_forum_page_breadcrumb', FALSE)),
111
    ),
112
  );
113
}
114
115
/**
116
 * Callback to get context placeholders provided by this handler.
117
 */
118
function advanced_forum_forum_get_contexts($task, $subtask_id) {
119
  return ctools_context_get_placeholders_from_argument(advanced_forum_forum_get_arguments($task, $subtask_id));
120
}
121
122
/**
123
 * Callback to enable/disable the page from the UI.
124
 */
125
function advanced_forum_forum_enable($cache, $status) {
126 13c3c9b4 Assos Assos
  if ($status == NULL) {
127 85ad3d82 Assos Assos
    $status = FALSE;
128 13c3c9b4 Assos Assos
  }
129 85ad3d82 Assos Assos
  variable_set('advanced_forum_forum_disabled', $status);
130
}
131
132
/**
133
 * Settings page for this item.
134
 */
135
function advanced_forum_forum_page_settings($form, &$form_state) {
136
  if (empty($form_state['page']->update_values)) {
137
    $settings = array(
138
      'advanced_forum_forum_page_breadcrumb' => variable_get('advanced_forum_forum_page_breadcrumb', FALSE),
139
    );
140
  }
141
  else {
142
    $settings = $form_state['page']->update_values;
143
  }
144
145
  $form['advanced_forum_forum_page_breadcrumb'] = array(
146
    '#title' => t('Inject hierarchy of first term into breadcrumb trail'),
147
    '#type' => 'checkbox',
148
    '#default_value' => $settings['advanced_forum_forum_page_breadcrumb'],
149
    '#description' => t('If checked, taxonomy term parents will appear in the breadcrumb trail.'),
150
  );
151
152
  return $form;
153
}
154
155
/**
156
 * Copy form values into the page cache.
157
 */
158
function advanced_forum_forum_page_settings_submit($form, &$form_state) {
159
  $form_state['page']->update_values = $form_state['values'];
160
}
161
162
/**
163
 * Save when the page cache is saved.
164
 */
165
function advanced_forum_forum_page_save($subtask, $cache) {
166
  if (isset($cache->update_values)) {
167
    variable_set('advanced_forum_forum_page_breadcrumb', $cache->update_values['advanced_forum_forum_page_breadcrumb']);
168
  }
169
}
170
171 13c3c9b4 Assos Assos
/**
172
 * Access check.
173
 */
174 85ad3d82 Assos Assos
function advanced_forum_forum_access_check($task, $subtask_id, $contexts) {
175
  $context = reset($contexts);
176
  return node_access('view', $context->data);
177
}