View source
<?php
function advanced_forum_forum_page_manager_tasks() {
return array(
'task type' => 'page',
'title' => t('Forum page'),
'admin title' => t('Forum page'),
'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.'),
'admin path' => 'forum/%forum',
'hook menu' => 'advanced_forum_forum_menu',
'hook menu alter' => 'advanced_forum_forum_menu_alter',
'handler type' => 'context',
'get arguments' => 'advanced_forum_forum_get_arguments',
'get context placeholders' => 'advanced_forum_forum_get_contexts',
'disabled' => variable_get('advanced_forum_forum_disabled', TRUE),
'enable callback' => 'advanced_forum_forum_enable',
'operations' => array(
'settings' => array(
'title' => t('Settings'),
'description' => t('Edit name, path and other basic settings for the page.'),
'form' => 'advanced_forum_forum_page_settings',
),
),
'save subtask callback' => 'advanced_forum_forum_page_save',
);
}
function advanced_forum_forum_menu_alter(&$items, $task) {
if (variable_get('advanced_forum_forum_disabled', TRUE)) {
return;
}
$items['forum']['page callback'] = 'advanced_forum_forum_page';
$items['forum']['file path'] = $task['path'];
$items['forum']['file'] = $task['file'];
}
function advanced_forum_forum_page($tid = 0) {
$task = page_manager_get_task('forum');
ctools_include('context');
ctools_include('context-task-handler');
$contexts = ctools_context_handler_get_task_contexts($task, '', array(
$tid,
));
$output = ctools_context_handler_render($task, '', $contexts, array(
$tid,
));
if ($output === FALSE) {
$output = advanced_forum_page($tid);
}
return $output;
}
function advanced_forum_forum_get_arguments($task, $subtask_id) {
return array(
array(
'keyword' => 'forum',
'identifier' => t('Forum'),
'id' => 1,
'name' => 'forum_id',
'settings' => array(
'breadcrumb' => variable_get('advanced_forum_forum_page_breadcrumb', TRUE),
),
),
);
}
function advanced_forum_forum_get_contexts($task, $subtask_id) {
return ctools_context_get_placeholders_from_argument(advanced_forum_forum_get_arguments($task, $subtask_id));
}
function advanced_forum_forum_enable($cache, $status) {
variable_set('advanced_forum_forum_disabled', $status);
}
function advanced_forum_forum_page_settings(&$form, &$form_state) {
if (empty($form_state['page']->update_values)) {
$settings = array(
'advanced_forum_forum_page_breadcrumb' => variable_get('advanced_forum_forum_page_breadcrumb', TRUE),
);
}
else {
$settings = $form_state['page']->update_values;
}
$form['advanced_forum_forum_page_breadcrumb'] = array(
'#title' => t('Inject hierarchy of first term into breadcrumb trail'),
'#type' => 'checkbox',
'#default_value' => $settings['advanced_forum_forum_page_breadcrumb'],
'#description' => t('If checked, taxonomy term parents will appear in the breadcrumb trail.'),
);
}
function advanced_forum_forum_page_settings_submit(&$form, &$form_state) {
$form_state['page']->update_values = $form_state['values'];
}
function advanced_forum_forum_page_save($subtask, $cache) {
if (isset($cache->update_values)) {
variable_set('advanced_forum_forum_page_breadcrumb', $cache->update_values['advanced_forum_forum_page_breadcrumb']);
}
}