1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
if (module_exists('comment')) {
|
4 |
|
|
/**
|
5 |
|
|
* Plugins are described by creating a $plugin array which will be used
|
6 |
|
|
* by the system that includes this file.
|
7 |
|
|
*/
|
8 |
|
|
$plugin = array(
|
9 |
|
|
'single' => TRUE,
|
10 |
|
|
'title' => t('Comment form'),
|
11 |
|
|
'icon' => 'icon_node.png',
|
12 |
|
|
'description' => t('A form to add a new comment.'),
|
13 |
|
|
'required context' => new ctools_context_required(t('Node'), 'node'),
|
14 |
|
|
'category' => t('Node'),
|
15 |
|
|
'defaults' => array('anon_links' => FALSE),
|
16 |
|
|
);
|
17 |
|
|
}
|
18 |
|
|
|
19 |
|
|
function ctools_node_comment_form_content_type_render($subtype, $conf, $panel_args, $context) {
|
20 |
136a805a
|
Assos Assos
|
$node = isset($context->data) ? clone $context->data : NULL;
|
21 |
85ad3d82
|
Assos Assos
|
$block = new stdClass();
|
22 |
|
|
$block->module = 'comments';
|
23 |
|
|
$block->delta = $node->nid;
|
24 |
|
|
|
25 |
|
|
$block->title = t('Add comment');
|
26 |
|
|
|
27 |
|
|
if (empty($node)) {
|
28 |
|
|
$block->content = t('Comment form here.');
|
29 |
|
|
}
|
30 |
|
|
else if ($node->comment == COMMENT_NODE_OPEN) {
|
31 |
|
|
if (user_access('post comments')) {
|
32 |
|
|
$comment = new stdClass();
|
33 |
|
|
$comment->nid = $node->nid;
|
34 |
|
|
$comment->pid = NULL;
|
35 |
|
|
$form_state = array(
|
36 |
|
|
'ctools comment alter' => TRUE,
|
37 |
|
|
'node' => $node,
|
38 |
|
|
'build_info' => array(
|
39 |
|
|
'args' => array(
|
40 |
|
|
$comment,
|
41 |
|
|
),
|
42 |
|
|
),
|
43 |
|
|
);
|
44 |
|
|
$block->content = drupal_build_form('comment_node_' . $node->type . '_form', $form_state);
|
45 |
|
|
}
|
46 |
|
|
else if (!empty($conf['anon_links'])) {
|
47 |
|
|
$block->content = theme('comment_post_forbidden', array('node' => $node));
|
48 |
|
|
}
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
return $block;
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
function ctools_node_comment_form_content_type_admin_title($subtype, $conf, $context) {
|
55 |
|
|
return t('"@s" comment form', array('@s' => $context->identifier));
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
function ctools_node_comment_form_content_type_edit_form($form, &$form_state) {
|
59 |
|
|
$form['anon_links'] = array(
|
60 |
|
|
'#type' => 'checkbox',
|
61 |
|
|
'#title' => t('Shows links to register or login.'),
|
62 |
|
|
'#description' => t('If anonymous comments are not allowed, this will display the register and login links.'),
|
63 |
|
|
'#default_value' => $form_state['conf']['anon_links'],
|
64 |
|
|
);
|
65 |
|
|
return $form;
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
function ctools_node_comment_form_content_type_edit_form_submit($form, &$form_state) {
|
69 |
|
|
// For each part of the form defined in the 'defaults' array set when you
|
70 |
|
|
// defined the content type, copy the value from the form into the array
|
71 |
|
|
// of items to be saved. We don't ever want to use
|
72 |
|
|
// $form_state['conf'] = $form_state['values'] because values contains
|
73 |
|
|
// buttons, form id and other items we don't want stored. CTools will handle
|
74 |
|
|
// the actual form submission.
|
75 |
|
|
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
|
76 |
|
|
$form_state['conf'][$key] = $form_state['values'][$key];
|
77 |
|
|
}
|
78 |
|
|
}
|