node_updated.inc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * @file
  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 last updated date'),
  10. 'icon' => 'icon_node.png',
  11. 'description' => t('The date the referenced node was last updated.'),
  12. 'required context' => new ctools_context_required(t('Node'), 'node'),
  13. 'category' => t('Node'),
  14. 'defaults' => array(
  15. 'format' => 'small',
  16. ),
  17. );
  18. /**
  19. * Render the custom content type.
  20. */
  21. function ctools_node_updated_content_type_render($subtype, $conf, $panel_args, $context) {
  22. if (empty($context) || empty($context->data) || empty($context->data->nid)) {
  23. return;
  24. }
  25. // Get a shortcut to the node.
  26. $node = $context->data;
  27. // Build the content type block.
  28. $block = new stdClass();
  29. $block->module = 'node_updated';
  30. $block->title = t('Last updated date');
  31. $block->content = format_date(!empty($node->changed) ? $node->changed : $node->created, $conf['format']);
  32. $block->delta = $node->nid;
  33. return $block;
  34. }
  35. /**
  36. * Returns an edit form for custom type settings.
  37. */
  38. function ctools_node_updated_content_type_edit_form($form, &$form_state) {
  39. $conf = $form_state['conf'];
  40. $date_types = array();
  41. foreach (system_get_date_types() as $date_type => $definition) {
  42. $date_types[$date_type] = format_date(REQUEST_TIME, $date_type);
  43. }
  44. $form['format'] = array(
  45. '#title' => t('Date format'),
  46. '#type' => 'select',
  47. '#options' => $date_types,
  48. '#default_value' => $conf['format'],
  49. );
  50. return $form;
  51. }
  52. /**
  53. * Submit handler for the custom type settings form.
  54. */
  55. function ctools_node_updated_content_type_edit_form_submit($form, &$form_state) {
  56. // Copy everything from our defaults.
  57. foreach (array_keys($form_state['plugin']['defaults']) as $key) {
  58. $form_state['conf'][$key] = $form_state['values'][$key];
  59. }
  60. }
  61. /**
  62. * Returns the administrative title for a type.
  63. */
  64. function ctools_node_updated_content_type_admin_title($subtype, $conf, $context) {
  65. return t('"@s" last updated date', array('@s' => $context->identifier));
  66. }