node_comment_form.inc 2.6 KB

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