View source
<?php
if (module_exists('comment')) {
$plugin = array(
'single' => TRUE,
'title' => t('Comment form'),
'icon' => 'icon_node.png',
'description' => t('A form to add a new comment.'),
'required context' => new ctools_context_required(t('Node'), 'node'),
'category' => t('Node'),
'defaults' => array(
'anon_links' => FALSE,
),
);
}
function ctools_node_comment_form_content_type_render($subtype, $conf, $panel_args, $context) {
if (empty($context->data->nid)) {
return;
}
$node = clone $context->data;
$block = new stdClass();
$block->module = 'comments';
$block->delta = $node->nid;
$block->title = t('Add comment');
if ($node->comment == COMMENT_NODE_OPEN) {
if (user_access('post comments')) {
$comment = new stdClass();
$comment->nid = $node->nid;
$comment->pid = NULL;
$form_state = array(
'ctools comment alter' => TRUE,
'node' => $node,
'build_info' => array(
'args' => array(
$comment,
),
),
);
$block->content = drupal_build_form('comment_node_' . $node->type . '_form', $form_state);
}
elseif (!empty($conf['anon_links'])) {
$block->content = theme('comment_post_forbidden', array(
'node' => $node,
));
}
}
return $block;
}
function ctools_node_comment_form_content_type_admin_title($subtype, $conf, $context) {
return t('"@s" comment form', array(
'@s' => $context->identifier,
));
}
function ctools_node_comment_form_content_type_edit_form($form, &$form_state) {
$form['anon_links'] = array(
'#type' => 'checkbox',
'#title' => t('Shows links to register or login.'),
'#description' => t('If anonymous comments are not allowed, this will display the register and login links.'),
'#default_value' => $form_state['conf']['anon_links'],
);
return $form;
}
function ctools_node_comment_form_content_type_edit_form_submit($form, &$form_state) {
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
$form_state['conf'][$key] = $form_state['values'][$key];
}
}