Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ctools / page_manager / plugins / tasks / comment_reply.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_comment_reply_page_manager_tasks() {
12
  if (!module_exists('comment')) {
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('Comment Reply page'),
21
    'admin title' => t('Comment Reply 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' => 'comment/reply/%node',
24

    
25
    // Menu hooks so that we can alter the node/%node menu entry to point to us.
26
    'hook menu alter' => 'page_manager_comment_reply_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
    'get arguments' => 'page_manager_comment_reply_get_arguments',
32
    'get context placeholders' => 'page_manager_comment_reply_get_contexts',
33

    
34
  // Allow this to be enabled or disabled:
35
    'disabled' => variable_get('page_manager_comment_reply_disabled', TRUE),
36
    'enable callback' => 'page_manager_comment_reply_enable',
37
    'access callback' => 'page_manager_comment_reply_check',
38
  );
39
}
40

    
41
/**
42
 * Callback to enable/disable the page from the UI.
43
 */
44
function page_manager_comment_reply_enable($cache, $status) {
45
  variable_set('page_manager_comment_reply_disabled', $status);
46
  // Set a global flag so that the menu routine knows it needs
47
  // to set a message if enabling cannot be done.
48
  if (!$status) {
49
    $GLOBALS['page_manager_enabling_comment_reply'] = TRUE;
50
  }
51
}
52

    
53
/**
54
 * Entry point for our overridden comment.
55
 */
56
function page_manager_comment_reply_page($node, $pid = NULL) {
57
  // Load my task plugin.
58
  $task = page_manager_get_task('comment_reply');
59

    
60
  // Load the node into a context.
61
  ctools_include('context');
62
  ctools_include('context-task-handler');
63

    
64
  $contexts = ctools_context_handler_get_task_contexts($task, '', array($node, $pid));
65

    
66
  if (array_key_exists('argument_cid_3', $contexts) && $contexts['argument_cid_3']->data->nid != $node->nid) {
67
    // Attempting to reply to a comment not belonging to the current nid.
68
    drupal_set_message(t('The comment you are replying to does not exist.'), 'error');
69
    drupal_goto("node/$node->nid");
70
  }
71

    
72
  $output = ctools_context_handler_render($task, '', $contexts, array($node, $pid));
73
  if ($output !== FALSE) {
74
    return $output;
75
  }
76

    
77
  $function = 'comment_reply';
78
  foreach (module_implements('page_manager_override') as $module) {
79
    $call = $module . '_page_manager_override';
80
    if (($rc = $call('comment_reply')) && function_exists($rc)) {
81
      $function = $rc;
82
      break;
83
    }
84
  }
85

    
86
  module_load_include('inc', 'comment', 'comment.pages');
87
  return $function($node, $pid);
88
}
89

    
90
/**
91
 * Callback to get arguments provided by this task handler.
92
 *
93
 * Since this is the node view and there is no UI on the arguments, we
94
 * create dummy arguments that contain the needed data.
95
 */
96
function page_manager_comment_reply_get_arguments($task, $subtask_id) {
97
  return array(
98
    array(
99
      'keyword' => 'node',
100
      'identifier' => t('Node being commented on'),
101
      'id' => 2,
102
      'name' => 'entity_id:node',
103
      'settings' => array(),
104
    ),
105
    array(
106
      'keyword' => 'comment',
107
      'identifier' => t('Comment being replied to'),
108
      'id' => 3,
109
      'name' => 'entity_id:comment',
110
      'settings' => array(),
111
    ),
112
  );
113
}
114

    
115
/**
116
 * Callback to get context placeholders provided by this handler.
117
 */
118
function page_manager_comment_reply_get_contexts($task, $subtask_id) {
119
  return ctools_context_get_placeholders_from_argument(page_manager_comment_reply_get_arguments($task, $subtask_id));
120
}
121

    
122
/**
123
 * Callback defined by page_manager_node_view_page_manager_tasks().
124
 *
125
 * Alter the node view input so that node view comes to us rather than the
126
 * normal node view process.
127
 */
128
function page_manager_comment_reply_menu_alter(&$items, $task) {
129
  if (variable_get('page_manager_comment_reply_disabled', TRUE)) {
130
    return;
131
  }
132
  // Override the node view handler for our purpose.
133
  $callback = $items['comment/reply/%node']['page callback'];
134
  if ($callback == 'comment_reply' || variable_get('page_manager_override_anyway', FALSE)) {
135
    $items['comment/reply/%node']['page callback'] = 'page_manager_comment_reply_page';
136
    $items['comment/reply/%node']['file path'] = $task['path'];
137
    $items['comment/reply/%node']['file'] = $task['file'];
138
  }
139
  else {
140
    // Automatically disable this task if it cannot be enabled.
141
    variable_set('page_manager_comment_reply_disabled', TRUE);
142
    if (!empty($GLOBALS['page_manager_enabling_comment_reply'])) {
143
      drupal_set_message(t('Page manager module is unable to enable comment/reply/%node because some other module already has overridden with %callback.', array('%callback' => $callback)), 'error');
144
    }
145
  }
146

    
147
  // @todo override node revision handler as well?
148
}
149

    
150
/**
151
 * Callback to determine if a page is accessible.
152
 *
153
 * @param $task
154
 *   The task plugin.
155
 * @param $subtask_id
156
 *   The subtask id
157
 * @param $contexts
158
 *   The contexts loaded for the task.
159
 *
160
 * @return
161
 *   TRUE if the current user can access the page.
162
 */
163
function page_manager_comment_reply_access_check($task, $subtask_id, $contexts) {
164
  $context = reset($contexts);
165
  return TRUE;
166
}