Projet

Général

Profil

Paste
Télécharger (4,08 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / page_manager / plugins / tasks / contact_site.inc @ c304a780

1
<?php
2

    
3
/**
4
 * @file
5
 */
6

    
7
/**
8
 * Specialized implementation of hook_page_manager_task_tasks(). See api-task.html for
9
 * more information.
10
 */
11
function page_manager_contact_site_page_manager_tasks() {
12
  if (!module_exists('contact')) {
13
    return;
14
  }
15

    
16
  return array(
17
    // This is a 'page' task and will fall under the page admin UI.
18
    'task type' => 'page',
19

    
20
    'title' => t('Site contact page'),
21
    'admin title' => t('Site contact page'),
22
    'admin description' => t('When enabled, this overrides the default Drupal behavior for the site contact page at <em>/contact</em>. If no variant is selected, the default Drupal contact form will be used.'),
23
    'admin path' => 'contact',
24

    
25
    // Menu hooks so that we can alter the node/%node menu entry to point to us.
26
    'hook menu alter' => 'page_manager_contact_site_menu_alter',
27

    
28
    // This is task uses 'context' handlers and must implement these to give the
29
    // handler data it needs.
30
    'handler type' => 'context',
31

    
32
    // Allow this to be enabled or disabled:
33
    'disabled' => variable_get('page_manager_contact_site_disabled', TRUE),
34
    'enable callback' => 'page_manager_contact_site_enable',
35
    'access callback' => 'page_manager_contact_access_check',
36
  );
37
}
38

    
39
/**
40
 * Callback defined by page_manager_contact_site_page_manager_tasks().
41
 *
42
 * Alter the node edit input so that node edit comes to us rather than the
43
 * normal node edit process.
44
 */
45
function page_manager_contact_site_menu_alter(&$items, $task) {
46
  if (variable_get('page_manager_contact_site_disabled', TRUE)) {
47
    return;
48
  }
49

    
50
  $callback = $items['contact']['page callback'];
51
  if ($callback == 'drupal_get_form') {
52
    $callback = $items['contact']['page arguments'][0];
53
  }
54

    
55
  // Override the node edit handler for our purpose.
56
  if ($callback == 'contact_site_form' || variable_get('page_manager_override_anyway', FALSE)) {
57
    $items['contact']['page callback'] = 'page_manager_contact_site';
58
    $items['contact']['file path'] = $task['path'];
59
    $items['contact']['file'] = $task['file'];
60
  }
61
  else {
62
    variable_set('page_manager_contact_site_disabled', TRUE);
63
    if (!empty($GLOBALS['page_manager_enabling_contact_site'])) {
64
      drupal_set_message(t('Page manager module is unable to enable contact because some other module already has overridden with %callback.', array('%callback' => $callback)), 'warning');
65
    }
66
    return;
67
  }
68

    
69
}
70

    
71
/**
72
 * Entry point for our overridden site contact.
73
 *
74
 * This function asks its assigned handlers who, if anyone, would like
75
 * to run with it. If no one does, it passes through to Drupal core's
76
 * node edit, which is node_page_edit().
77
 */
78
function page_manager_contact_site() {
79
  // Load my task plugin.
80
  $task = page_manager_get_task('contact_site');
81

    
82
  ctools_include('context');
83
  ctools_include('context-task-handler');
84
  $output = ctools_context_handler_render($task, '', array(), array());
85
  if ($output !== FALSE) {
86
    return $output;
87
  }
88

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

    
99
  // Otherwise, fall back.
100
  if ($function == 'contact_site_form') {
101
    return drupal_get_form($function);
102
  }
103

    
104
  return $function();
105
}
106

    
107
/**
108
 * Callback to enable/disable the page from the UI.
109
 */
110
function page_manager_contact_site_enable($cache, $status) {
111
  variable_set('page_manager_contact_site_disabled', $status);
112
  // Set a global flag so that the menu routine knows it needs
113
  // to set a message if enabling cannot be done.
114
  if (!$status) {
115
    $GLOBALS['page_manager_enabling_contact_site'] = TRUE;
116
  }
117
}
118

    
119
/**
120
 * Callback to determine if a page is accessible.
121
 *
122
 * @param $task
123
 *   The task plugin.
124
 * @param $subtask_id
125
 *   The subtask id
126
 * @param $contexts
127
 *   The contexts loaded for the task.
128
 *
129
 * @return
130
 *   TRUE if the current user can access the page.
131
 */
132
function page_manager_contact_access_check($task, $subtask_id, $contexts) {
133
  return user_access('access site-wide contact form');
134
}