Projet

Général

Profil

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

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

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

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

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

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

    
37
  return $block;
38
}
39

    
40
/**
41
 * Returns an edit form for custom type settings.
42
 */
43
function ctools_node_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_node_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_node_created_content_type_admin_title($subtype, $conf, $context) {
73
  return t('"@s" created date', array('@s' => $context->identifier));
74
}