summaryrefslogtreecommitdiff
path: root/sites/all/modules/ctools/plugins/content_types/comment/comment_created.inc
blob: 62944e7127a4e77b6a4ba112023c8b054fea5960 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php

/**
 * Plugins are described by creating a $plugin array which will be used
 * by the system that includes this file.
 */
$plugin = array(
  'single' => TRUE,
  'title' => t('Comment created date'),
  'icon' => 'icon_comment.png',
  'description' => t('The date the referenced comment was created.'),
  'required context' => new ctools_context_required(t('Comment'), 'entity:comment'),
  'category' => t('Comment'),
  'defaults' => array(
    'format' => 'small',
  ),
);

/**
 * Render the custom content type.
 */
function ctools_comment_created_content_type_render($subtype, $conf, $panel_args, $context) {
  if (empty($context) || empty($context->data)) {
    return;
  }

  // Get a shortcut to the comment.
  $comment = $context->data;

  // Build the content type block.
  $block = new stdClass();
  $block->module  = 'comment_created';
  $block->title   = t('Created date');
  $block->content = format_date($comment->created, $conf['format']);
  $block->delta   = $comment->cid;

  return $block;
}

/**
 * Returns an edit form for custom type settings.
 */
function ctools_comment_created_content_type_edit_form($form, &$form_state) {
  $conf = $form_state['conf'];
  $date_types = array();

  foreach (system_get_date_types() as $date_type => $definition) {
    $date_types[$date_type] = format_date(REQUEST_TIME, $date_type);
  }
  $form['format'] = array(
    '#title' => t('Date format'),
    '#type' => 'select',
    '#options' => $date_types,
    '#default_value' => $conf['format'],
  );
  return $form;
}

/**
 * Submit handler for the custom type settings form.
 */
function ctools_comment_created_content_type_edit_form_submit($form, &$form_state) {
  // Copy everything from our defaults.
  foreach (array_keys($form_state['plugin']['defaults']) as $key) {
    $form_state['conf'][$key] = $form_state['values'][$key];
  }
}

/**
 * Returns the administrative title for a type.
 */
function ctools_comment_created_content_type_admin_title($subtype, $conf, $context) {
  return t('"@s" created date', array('@s' => $context->identifier));
}