Projet

Général

Profil

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

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

1
<?php
2

    
3
/**
4
 * @file
5
 */
6

    
7
if (module_exists('comment')) {
8
  /**
9
   * Plugins are described by creating a $plugin array which will be used
10
   * by the system that includes this file.
11
   */
12
  $plugin = array(
13
    'single' => TRUE,
14
    'title' => t('Comment form'),
15
    'icon' => 'icon_node.png',
16
    'description' => t('A form to add a new comment.'),
17
    'required context' => new ctools_context_required(t('Node'), 'node'),
18
    'category' => t('Node'),
19
    'defaults' => array('anon_links' => FALSE),
20
  );
21
}
22

    
23
function ctools_node_comment_form_content_type_render($subtype, $conf, $panel_args, $context) {
24
  if (empty($context->data->nid)) {
25
    return;
26
  }
27
  $node = clone $context->data;
28
  $block = new stdClass();
29
  $block->module = 'comments';
30
  $block->delta = $node->nid;
31
  $block->title = t('Add comment');
32

    
33
  if ($node->comment == COMMENT_NODE_OPEN) {
34
    if (user_access('post comments')) {
35
      $comment = new stdClass();
36
      $comment->nid = $node->nid;
37
      $comment->pid = NULL;
38
      $form_state = array(
39
        'ctools comment alter' => TRUE,
40
        'node' => $node,
41
        'build_info' => array(
42
          'args' => array(
43
            $comment,
44
          ),
45
        ),
46
      );
47
      $block->content = drupal_build_form('comment_node_' . $node->type . '_form', $form_state);
48
    }
49
    elseif (!empty($conf['anon_links'])) {
50
      $block->content = theme('comment_post_forbidden', array('node' => $node));
51
    }
52
  }
53

    
54
  return $block;
55
}
56

    
57
function ctools_node_comment_form_content_type_admin_title($subtype, $conf, $context) {
58
  return t('"@s" comment form', array('@s' => $context->identifier));
59
}
60

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

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