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 last updated date'),
|
12
|
'icon' => 'icon_node.png',
|
13
|
'description' => t('The date the referenced node was last updated.'),
|
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_updated_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_updated';
|
35
|
$block->title = t('Last updated date');
|
36
|
$block->content = format_date(!empty($node->changed) ? $node->changed : $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_updated_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
|
|
53
|
$form['format'] = array(
|
54
|
'#title' => t('Date format'),
|
55
|
'#type' => 'select',
|
56
|
'#options' => $date_types,
|
57
|
'#default_value' => $conf['format'],
|
58
|
);
|
59
|
return $form;
|
60
|
}
|
61
|
|
62
|
/**
|
63
|
* Submit handler for the custom type settings form.
|
64
|
*/
|
65
|
function ctools_node_updated_content_type_edit_form_submit($form, &$form_state) {
|
66
|
// Copy everything from our defaults.
|
67
|
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
|
68
|
$form_state['conf'][$key] = $form_state['values'][$key];
|
69
|
}
|
70
|
}
|
71
|
|
72
|
/**
|
73
|
* Returns the administrative title for a type.
|
74
|
*/
|
75
|
function ctools_node_updated_content_type_admin_title($subtype, $conf, $context) {
|
76
|
return t('"@s" last updated date', array('@s' => $context->identifier));
|
77
|
}
|