5 * Handle the 'section view' override task.
7 * This plugin overrides section/%section and reroutes it to the page manager, where
8 * a list of tasks can be used to service this request based upon criteria
9 * supplied by access plugins.
13 * Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
16 function section_section_view_page_manager_tasks() {
18 // This is a 'page' task and will fall under the page admin UI
19 'task type' => 'page',
21 'title' => t('Section template'),
23 'admin title' => t('Section template'),
24 'admin description' => t('When enabled, this overrides the default behavior for displaying sections at <em>section/%section</em>.'),
25 'admin path' => 'section/%section',
27 // Menu hooks so that we can alter the section/%section menu entry to point to us.
28 'hook menu' => 'section_section_view_menu',
29 'hook menu alter' => 'section_section_view_menu_alter',
31 // This is task uses 'context' handlers and must implement these to give the
32 // handler data it needs.
33 'handler type' => 'context',
34 'get arguments' => 'section_section_view_get_arguments',
35 'get context placeholders' => 'section_section_view_get_contexts',
37 // Allow this to be enabled or disabled:
38 'disabled' => variable_get('section_section_view_disabled', TRUE
),
39 'enable callback' => 'section_section_view_enable',
44 * Callback defined by section_section_view_page_manager_tasks().
46 * Alter the node view input so that node view comes to us rather than the
47 * normal node view process.
49 function section_section_view_menu_alter(&$items, $task) {
50 if (variable_get('section_section_view_disabled', TRUE
)) {
54 // Override the node view handler for our purpose.
55 $callback = $items['section/%section']['page callback'];
56 if ($callback === 'section_page_view' || variable_get('page_manager_override_anyway', FALSE
)) {
57 $items['section/%section']['page callback'] = 'section_section_view_page';
58 $items['section/%section']['file path'] = $task['path'];
59 $items['section/%section']['file'] = $task['file'];
62 // automatically disable this task if it cannot be enabled.
63 variable_set('section_section_view_disabled', TRUE
);
64 if (!empty($GLOBALS['section_enabling_section_view'])) {
65 drupal_set_message(t('Page manager module is unable to enable section/%section because some other module already has overridden with %callback.', array('%callback' => $callback)), 'error');
71 * Entry point for our overridden section view.
73 * This function asks its assigned handlers who, if anyone, would like
74 * to run with it. If no one does, it passes through to sections
75 * section view, which is section_page_view().
77 function section_section_view_page($section) {
78 // Load my task plugin
79 $task = page_manager_get_task('section_view');
81 // Load the node into a context.
82 ctools_include('context');
83 ctools_include('context-task-handler');
84 $contexts = ctools_context_handler_get_task_contexts($task, '', array($section));
86 $output = ctools_context_handler_render($task, '', $contexts, array($section->sid
));
87 if ($output != FALSE
) {
91 $function = 'section_page_view';
92 foreach (module_implements('page_manager_override') as
$module) {
93 $call = $module .
'_page_manager_override';
94 if (($rc = $call('section_view')) && function_exists($rc)) {
100 // Otherwise, fall back.
101 return $function($section);
105 * Callback to get arguments provided by this task handler.
107 * Since this is the section view and there is no UI on the arguments, we
108 * create dummy arguments that contain the needed data.
110 function section_section_view_get_arguments($task, $subtask_id) {
113 'keyword' => 'section',
114 'identifier' => t('Section being viewed'),
116 'name' => 'entity_id:section',
117 'settings' => array(),
123 * Callback to get context placeholders provided by this handler.
125 function section_section_view_get_contexts($task, $subtask_id) {
126 return ctools_context_get_placeholders_from_argument(section_section_view_get_arguments($task, $subtask_id));
130 * Callback to enable/disable the page from the UI.
132 function section_section_view_enable($cache, $status) {
133 variable_set('section_section_view_disabled', $status);
135 // Set a global flag so that the menu routine knows it needs
136 // to set a message if enabling cannot be done.
138 $GLOBALS['section_enabling_section_view'] = TRUE
;