Project

General

Profile

Paste
Download (2.02 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / ctools / plugins / content_types / comment / comment_created.inc @ 560c3060

1
<?php
2

    
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 created date'),
10
  'icon' => 'icon_comment.png',
11
  'description' => t('The date the referenced comment was created.'),
12
  'required context' => new ctools_context_required(t('Comment'), 'entity:comment'),
13
  'category' => t('Comment'),
14
  'defaults' => array(
15
    'format' => 'small',
16
  ),
17
);
18

    
19
/**
20
 * Render the custom content type.
21
 */
22
function ctools_comment_created_content_type_render($subtype, $conf, $panel_args, $context) {
23
  if (empty($context) || empty($context->data)) {
24
    return;
25
  }
26

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

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

    
37
  return $block;
38
}
39

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

    
47
  foreach (system_get_date_types() as $date_type => $definition) {
48
    $date_types[$date_type] = format_date(REQUEST_TIME, $date_type);
49
  }
50
  $form['format'] = array(
51
    '#title' => t('Date format'),
52
    '#type' => 'select',
53
    '#options' => $date_types,
54
    '#default_value' => $conf['format'],
55
  );
56
  return $form;
57
}
58

    
59
/**
60
 * Submit handler for the custom type settings form.
61
 */
62
function ctools_comment_created_content_type_edit_form_submit($form, &$form_state) {
63
  // Copy everything from our defaults.
64
  foreach (array_keys($form_state['plugin']['defaults']) as $key) {
65
    $form_state['conf'][$key] = $form_state['values'][$key];
66
  }
67
}
68

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