node_comment_form.inc 2.6 KB

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