Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ctools / page_manager / plugins / tasks / user_view.inc @ e4c061ad

1
<?php
2

    
3
/**
4
 * @file
5
 * Overrides the user profile display at user/%user.
6
 *
7
 * Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
8
 * more information.
9
 */
10
function page_manager_user_view_page_manager_tasks() {
11
  return array(
12
    // This is a 'page' task and will fall under the page admin UI
13
    'task type' => 'page',
14
    'title' => t('User profile template'),
15
    'admin title' => t('User profile template'),
16
    'admin description' => t('When enabled, this overrides the default Drupal behavior for displaying user profiles at <em>user/%user</em>. If you add variants, you may use selection criteria such as roles or user access to provide different views of user profiles. If no variant is selected, the default Drupal user view will be used. Please note that if you are using pathauto, aliases may make a node to be somewhere else, but as far as Drupal is concerned, they are still at user/%user.'),
17
    'admin path' => 'user/%user',
18

    
19
    // Callback to add items to the page managertask administration form:
20
    'task admin' => 'page_manager_user_view_task_admin',
21

    
22
    'hook menu' => 'page_manager_user_view_menu',
23
    'hook menu alter' => 'page_manager_user_view_menu_alter',
24

    
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_user_view_get_arguments',
29
    'get context placeholders' => 'page_manager_user_view_get_contexts',
30

    
31
    // Allow this to be enabled or disabled:
32
    'disabled' => variable_get('page_manager_user_view_disabled', TRUE),
33
    'enable callback' => 'page_manager_user_view_enable',
34
    'access callback' => 'page_manager_user_view_access_check',
35
  );
36
}
37

    
38
/**
39
 * Callback defined by page_manager_user_view_page_manager_tasks().
40
 *
41
 * Alter the user view input so that user view comes to us rather than the
42
 * normal user view process.
43
 */
44
function page_manager_user_view_menu_alter(&$items, $task) {
45
  if (variable_get('page_manager_user_view_disabled', TRUE)) {
46
    return;
47
  }
48

    
49
  // Override the user view handler for our purpose.
50
  if ($items['user/%user']['page callback'] == 'user_view_page' || variable_get('page_manager_override_anyway', FALSE)) {
51
    $items['user/%user']['page callback'] = 'page_manager_user_view_page';
52
    $items['user/%user']['file path'] = $task['path'];
53
    $items['user/%user']['file'] = $task['file'];
54
  }
55
  else {
56
    // automatically disable this task if it cannot be enabled.
57
    variable_set('page_manager_user_view_disabled', TRUE);
58
    if (!empty($GLOBALS['page_manager_enabling_user_view'])) {
59
      drupal_set_message(t('Page manager module is unable to enable user/%user because some other module already has overridden with %callback.', array('%callback' => $items['user/%user']['page callback'])), 'error');
60
    }
61
  }
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 Drupal core's
69
 * user view, which is user_page_view().
70
 */
71
function page_manager_user_view_page($account) {
72
  // Load my task plugin:
73
  $task = page_manager_get_task('user_view');
74

    
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));
79

    
80
  // Build content. @todo -- this may not be right.
81
  user_build_content($account);
82

    
83
  $output = ctools_context_handler_render($task, '', $contexts, array($account->uid));
84
  if ($output !== FALSE) {
85
    return $output;
86
  }
87

    
88
  $function = 'user_view';
89
  foreach (module_implements('page_manager_override') as $module) {
90
    $call = $module . '_page_manager_override';
91
    if (($rc = $call('user_view')) && function_exists($rc)) {
92
      $function = $rc;
93
      break;
94
    }
95
  }
96

    
97
  // Otherwise, fall back.
98
  if ($function == 'user_view') {
99
    module_load_include('inc', 'user', 'user.pages');
100
  }
101
  //fire off "view" op so that triggers still work
102
  // @todo -- this doesn't work anymore, and the alternatives seem bad.
103
  // will have to figure out how to fix this.
104
//  user_module_invoke('view', $array = array(), $account);
105
  return $function($account);
106
}
107

    
108
/**
109
 * Callback to get arguments provided by this task handler.
110
 *
111
 * Since this is the node view and there is no UI on the arguments, we
112
 * create dummy arguments that contain the needed data.
113
 */
114
function page_manager_user_view_get_arguments($task, $subtask_id) {
115
  return array(
116
    array(
117
      'keyword' => 'user',
118
      'identifier' => t('User being viewed'),
119
      'id' => 1,
120
      'name' => 'entity_id:user',
121
      'settings' => array(),
122
    ),
123
  );
124
}
125

    
126
/**
127
 * Callback to get context placeholders provided by this handler.
128
 */
129
function page_manager_user_view_get_contexts($task, $subtask_id) {
130
  return ctools_context_get_placeholders_from_argument(page_manager_user_view_get_arguments($task, $subtask_id));
131
}
132

    
133
/**
134
 * Callback to enable/disable the page from the UI.
135
 */
136
function page_manager_user_view_enable($cache, $status) {
137
  variable_set('page_manager_user_view_disabled', $status);
138

    
139
  // Set a global flag so that the menu routine knows it needs
140
  // to set a message if enabling cannot be done.
141
  if (!$status) {
142
    $GLOBALS['page_manager_enabling_user_view'] = TRUE;
143
  }
144
}
145

    
146
/**
147
 * Callback to determine if a page is accessible.
148
 *
149
 * @param $task
150
 *   The task plugin.
151
 * @param $subtask_id
152
 *   The subtask id
153
 * @param $contexts
154
 *   The contexts loaded for the task.
155
 * @return
156
 *   TRUE if the current user can access the page.
157
 */
158
function page_manager_user_view_access_check($task, $subtask_id, $contexts) {
159
  $context = reset($contexts);
160
  return user_view_access($context->data);
161
}