Projet

Général

Profil

Paste
Télécharger (2,54 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / plugins / content_types / node_context / node_comment_form.inc @ 7e72b748

1
<?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
  if (empty($context->data->nid)) {
21
    return;
22
  }
23
  $node = clone $context->data;
24
  $block = new stdClass();
25
  $block->module = 'comments';
26
  $block->delta  = $node->nid;
27
  $block->title = t('Add comment');
28

    
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
    else if (!empty($conf['anon_links'])) {
46
      $block->content = theme('comment_post_forbidden', array('node' => $node));
47
    }
48
  }
49

    
50
  return $block;
51
}
52

    
53
function ctools_node_comment_form_content_type_admin_title($subtype, $conf, $context) {
54
  return t('"@s" comment form', array('@s' => $context->identifier));
55
}
56

    
57
function ctools_node_comment_form_content_type_edit_form($form, &$form_state) {
58
  $form['anon_links'] = array(
59
    '#type'  => 'checkbox',
60
    '#title' => t('Shows links to register or login.'),
61
    '#description' => t('If anonymous comments are not allowed, this will display the register and login links.'),
62
    '#default_value' => $form_state['conf']['anon_links'],
63
  );
64
  return $form;
65
}
66

    
67
function ctools_node_comment_form_content_type_edit_form_submit($form, &$form_state) {
68
  // For each part of the form defined in the 'defaults' array set when you
69
  // defined the content type, copy the value from the form into the array
70
  // of items to be saved. We don't ever want to use
71
  // $form_state['conf'] = $form_state['values'] because values contains
72
  // buttons, form id and other items we don't want stored. CTools will handle
73
  // the actual form submission.
74
  foreach (array_keys($form_state['plugin']['defaults']) as $key) {
75
    $form_state['conf'][$key] = $form_state['values'][$key];
76
  }
77
}
78