Projet

Général

Profil

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

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

1
<?php
2

    
3
/**
4
 * @file
5
 * Plugins are described by creating a $plugin array which will be used
6
 * by the system that includes this file.
7
 */
8

    
9
$plugin = array(
10
  'single' => TRUE,
11
  'title' => t('Node created date'),
12
  'icon' => 'icon_node.png',
13
  'description' => t('The date the referenced node was created.'),
14
  'required context' => new ctools_context_required(t('Node'), 'node'),
15
  'category' => t('Node'),
16
  'defaults' => array(
17
    'format' => 'small',
18
  ),
19
);
20

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

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

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

    
39
  return $block;
40
}
41

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

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

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

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