Projet

Général

Profil

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

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

1
<?php
2

    
3
/**
4
 * Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
5
 * more information.
6
 */
7
function page_manager_contact_user_page_manager_tasks() {
8
  if (!module_exists('contact')) {
9
    return;
10
  }
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 contact'),
15
    'admin title' => t('User contact'),
16
    'admin description' => t('When enabled, this overrides the default Drupal behavior for displaying the user contact form at <em>user/%user/contact</em>. If no variant is selected, the default Drupal user contact form will be used.'),
17
    'admin path' => 'user/%user/contact',
18

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

    
22
    'hook menu alter' => 'page_manager_contact_user_menu_alter',
23

    
24
    // This is task uses 'context' handlers and must implement these to give the
25
    // handler data it needs.
26
    'handler type' => 'context', // handler type -- misnamed
27
    'get arguments' => 'page_manager_contact_user_get_arguments',
28
    'get context placeholders' => 'page_manager_contact_user_get_contexts',
29

    
30
    // Allow this to be enabled or disabled:
31
    'disabled' => variable_get('page_manager_contact_user_disabled', TRUE),
32
    'enable callback' => 'page_manager_contact_user_enable',
33
    'access callback' => 'page_manager_contact_user_access_check',
34
  );
35
}
36

    
37
/**
38
 * Callback defined by page_manager_contact_user_page_manager_tasks().
39
 *
40
 * Alter the user view input so that user view comes to us rather than the
41
 * normal user view process.
42
 */
43
function page_manager_contact_user_menu_alter(&$items, $task) {
44
  if (variable_get('page_manager_contact_user_disabled', TRUE)) {
45
    return;
46
  }
47
  $callback = $items['user/%user/contact']['page callback'];
48
  if ($callback == 'drupal_get_form') {
49
    $callback = $items['user/%user/contact']['page arguments'][0];
50
  }
51

    
52
  // Override the user view handler for our purpose.
53
  if ($callback == 'contact_personal_form' || variable_get('page_manager_override_anyway', FALSE)) {
54
    $items['user/%user/contact']['page callback'] = 'page_manager_contact_user';
55
    $items['user/%user/contact']['file path'] = $task['path'];
56
    $items['user/%user/contact']['file'] = $task['file'];
57
  }
58
  else {
59
    // automatically disable this task if it cannot be enabled.
60
    variable_set('page_manager_contact_user_disabled', TRUE);
61
    if (!empty($GLOBALS['page_manager_enabling_contact_user'])) {
62
      drupal_set_message(t('Page manager module is unable to enable user/%user/contact because some other module already has overridden with %callback.', array('%callback' => $callback)), 'error');
63
    }
64
  }
65
}
66

    
67
/**
68
 * Entry point for our overridden user view.
69
 *
70
 * This function asks its assigned handlers who, if anyone, would like
71
 * to run with it. If no one does, it passes through to Drupal core's
72
 * user view, which is user_page_view().
73
 */
74
function page_manager_contact_user($form_id, $account) {
75
  // Load my task plugin:
76
  $task = page_manager_get_task('contact_user');
77

    
78
  // Load the account into a context.
79
  ctools_include('context');
80
  ctools_include('context-task-handler');
81
  $contexts = ctools_context_handler_get_task_contexts($task, '', array($account));
82

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

    
88
  module_load_include('inc', 'contact', 'contact.pages');
89
  $function = 'contact_personal_form';
90
  foreach (module_implements('page_manager_override') as $module) {
91
    $call = $module . '_page_manager_override';
92
    if (($rc = $call('contact_user')) && function_exists($rc)) {
93
      $function = $rc;
94
      break;
95
    }
96
  }
97

    
98
  // Otherwise, fall back.
99
  return drupal_get_form($function, $account);
100
}
101

    
102
/**
103
 * Callback to get arguments provided by this task handler.
104
 *
105
 * Since this is the node view and there is no UI on the arguments, we
106
 * create dummy arguments that contain the needed data.
107
 */
108
function page_manager_contact_user_get_arguments($task, $subtask_id) {
109
  return array(
110
    array(
111
      'keyword' => 'user',
112
      'identifier' => t('User being viewed'),
113
      'id' => 1,
114
      'name' => 'uid',
115
      'settings' => array(),
116
    ),
117
  );
118
}
119

    
120
/**
121
 * Callback to get context placeholders provided by this handler.
122
 */
123
function page_manager_contact_user_get_contexts($task, $subtask_id) {
124
  return ctools_context_get_placeholders_from_argument(page_manager_contact_user_get_arguments($task, $subtask_id));
125
}
126

    
127
/**
128
 * Callback to enable/disable the page from the UI.
129
 */
130
function page_manager_contact_user_enable($cache, $status) {
131
  variable_set('page_manager_contact_user_disabled', $status);
132

    
133
  // Set a global flag so that the menu routine knows it needs
134
  // to set a message if enabling cannot be done.
135
  if (!$status) {
136
    $GLOBALS['page_manager_enabling_contact_user'] = TRUE;
137
  }
138
}
139

    
140
/**
141
 * Callback to determine if a page is accessible.
142
 *
143
 * @param $task
144
 *   The task plugin.
145
 * @param $subtask_id
146
 *   The subtask id
147
 * @param $contexts
148
 *   The contexts loaded for the task.
149
 * @return
150
 *   TRUE if the current user can access the page.
151
 */
152
function page_manager_blog_contact_user_access_check($task, $subtask_id, $contexts) {
153
  $context = reset($contexts);
154
  return _contact_personal_tab_access($context->data);
155
}