node_created.inc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 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. * Render the custom content type.
  20. */
  21. function ctools_node_created_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_created';
  30. $block->title = t('Created date');
  31. $block->content = format_date($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_created_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_created_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_created_content_type_admin_title($subtype, $conf, $context) {
  65. return t('"@s" created date', array('@s' => $context->identifier));
  66. }