comment_created.inc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Plugins are described by creating a $plugin array which will be used
  4. * by the system that includes this file.
  5. */
  6. $plugin = array(
  7. 'single' => TRUE,
  8. 'title' => t('Comment created date'),
  9. 'icon' => 'icon_comment.png',
  10. 'description' => t('The date the referenced comment was created.'),
  11. 'required context' => new ctools_context_required(t('Comment'), 'entity:comment'),
  12. 'category' => t('Comment'),
  13. 'defaults' => array(
  14. 'format' => 'small',
  15. ),
  16. );
  17. /**
  18. * Render the custom content type.
  19. */
  20. function ctools_comment_created_content_type_render($subtype, $conf, $panel_args, $context) {
  21. if (empty($context) || empty($context->data)) {
  22. return;
  23. }
  24. // Get a shortcut to the comment.
  25. $comment = $context->data;
  26. // Build the content type block.
  27. $block = new stdClass();
  28. $block->module = 'comment_created';
  29. $block->title = t('Created date');
  30. $block->content = format_date($comment->created, $conf['format']);
  31. $block->delta = $comment->cid;
  32. return $block;
  33. }
  34. /**
  35. * Returns an edit form for custom type settings.
  36. */
  37. function ctools_comment_created_content_type_edit_form($form, &$form_state) {
  38. $conf = $form_state['conf'];
  39. $date_types = array();
  40. foreach (system_get_date_types() as $date_type => $definition) {
  41. $date_types[$date_type] = format_date(REQUEST_TIME, $date_type);
  42. }
  43. $form['format'] = array(
  44. '#title' => t('Date format'),
  45. '#type' => 'select',
  46. '#options' => $date_types,
  47. '#default_value' => $conf['format'],
  48. );
  49. return $form;
  50. }
  51. /**
  52. * Submit handler for the custom type settings form.
  53. */
  54. function ctools_comment_created_content_type_edit_form_submit($form, &$form_state) {
  55. // Copy everything from our defaults.
  56. foreach (array_keys($form_state['plugin']['defaults']) as $key) {
  57. $form_state['conf'][$key] = $form_state['values'][$key];
  58. }
  59. }
  60. /**
  61. * Returns the administrative title for a type.
  62. */
  63. function ctools_comment_created_content_type_admin_title($subtype, $conf, $context) {
  64. return t('"@s" created date', array('@s' => $context->identifier));
  65. }