4 * Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
7 function page_manager_blog_user_page_manager_tasks() {
8 if (!module_exists('blog')) {
13 // This is a 'page' task and will fall under the page admin UI
14 'task type' => 'page',
15 'title' => t('User blog'),
16 'admin title' => t('User blog'),
17 'admin description' => t('When enabled, this overrides the default Drupal behavior for displaying user blogs at <em>blog/%user</em>. If no variant is selected, the default Drupal user blog will be used.'),
18 'admin path' => 'blog/%user',
20 // Callback to add items to the page managertask administration form:
21 'task admin' => 'page_manager_blog_user_task_admin',
23 'hook menu alter' => 'page_manager_blog_user_menu_alter',
25 // This is task uses 'context' handlers and must implement these to give the
26 // handler data it needs.
27 'handler type' => 'context', // handler type -- misnamed
28 'get arguments' => 'page_manager_blog_user_get_arguments',
29 'get context placeholders' => 'page_manager_blog_user_get_contexts',
31 // Allow this to be enabled or disabled:
32 'disabled' => variable_get('page_manager_blog_user_disabled', TRUE),
33 'enable callback' => 'page_manager_blog_user_enable',
34 'access callback' => 'page_manager_blog_user_access_check',
39 * Callback defined by page_manager_blog_user_page_manager_tasks().
41 * Alter the user view input so that user view comes to us rather than the
42 * normal user view process.
44 function page_manager_blog_user_menu_alter(&$items, $task) {
45 if (variable_get('page_manager_blog_user_disabled', TRUE)) {
49 // Override the user view handler for our purpose.
50 if ($items['blog/%user_uid_optional']['page callback'] == 'blog_page_user' || variable_get('page_manager_override_anyway', FALSE)) {
51 $items['blog/%user_uid_optional']['page callback'] = 'page_manager_blog_user';
52 $items['blog/%user_uid_optional']['file path'] = $task['path'];
53 $items['blog/%user_uid_optional']['file'] = $task['file'];
56 // automatically disable this task if it cannot be enabled.
57 variable_set('page_manager_blog_user_disabled', TRUE);
58 if (!empty($GLOBALS['page_manager_enabling_blog_user'])) {
59 drupal_set_message(t('Page manager module is unable to enable blog/%user because some other module already has overridden with %callback.', array('%callback' => $items['blog/%user']['page callback'])), 'error');
65 * Entry point for our overridden user view.
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 Drupal core's
69 * user view, which is user_page_view().
71 function page_manager_blog_user($account) {
72 // Load my task plugin:
73 $task = page_manager_get_task('blog_user');
75 // Load the account into a context.
76 ctools_include('context');
77 ctools_include('context-task-handler');
78 $contexts = ctools_context_handler_get_task_contexts($task, '', array($account));
80 $output = ctools_context_handler_render($task, '', $contexts, array($account->uid));
81 if ($output !== FALSE) {
85 module_load_include('inc', 'blog', 'blog.pages');
86 $function = 'blog_page_user';
87 foreach (module_implements('page_manager_override') as $module) {
88 $call = $module . '_page_manager_override';
89 if (($rc = $call('blog_user')) && function_exists($rc)) {
95 // Otherwise, fall back.
96 return $function($account);
100 * Callback to get arguments provided by this task handler.
102 * Since this is the node view and there is no UI on the arguments, we
103 * create dummy arguments that contain the needed data.
105 function page_manager_blog_user_get_arguments($task, $subtask_id) {
109 'identifier' => t('User being viewed'),
112 'settings' => array(),
118 * Callback to get context placeholders provided by this handler.
120 function page_manager_blog_user_get_contexts($task, $subtask_id) {
121 return ctools_context_get_placeholders_from_argument(page_manager_blog_user_get_arguments($task, $subtask_id));
125 * Callback to enable/disable the page from the UI.
127 function page_manager_blog_user_enable($cache, $status) {
128 variable_set('page_manager_blog_user_disabled', $status);
130 // Set a global flag so that the menu routine knows it needs
131 // to set a message if enabling cannot be done.
133 $GLOBALS['page_manager_enabling_blog_user'] = TRUE;
138 * Callback to determine if a page is accessible.
145 * The contexts loaded for the task.
147 * TRUE if the current user can access the page.
149 function page_manager_blog_user_access_check($task, $subtask_id, $contexts) {
150 $context = reset($contexts);
151 return blog_page_user_access($context->data);