comment_links.inc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 links'),
  9. 'icon' => 'icon_comment.png',
  10. 'description' => t('Comment links of the referenced comment.'),
  11. 'required context' => new ctools_context_required(t('Comment'), 'entity:comment'),
  12. 'category' => t('Comment'),
  13. 'defaults' => array(
  14. 'override_title' => FALSE,
  15. 'override_title_text' => '',
  16. 'build_mode' => '',
  17. ),
  18. );
  19. /**
  20. * Output function for the comment links.
  21. */
  22. function ctools_comment_links_content_type_render($subtype, $conf, $panel_args, $context) {
  23. if (!empty($context) && empty($context->data)) {
  24. return;
  25. }
  26. $comment = isset($context->data) ? clone $context->data : NULL;
  27. $block = new stdClass();
  28. $block->module = 'comment';
  29. $block->delta = $comment->cid;
  30. if (empty($comment)) {
  31. $block->delta = 'placeholder';
  32. $block->subject = t('Comment subject.');
  33. $block->content = t('Comment links go here.');
  34. }
  35. else {
  36. $node = node_load($comment->nid);
  37. $block->subject = $comment->subject;
  38. comment_build_content($comment, $node, $conf['build_mode']);
  39. $block->content = $comment->content['links'];
  40. }
  41. return $block;
  42. }
  43. /**
  44. * Returns an edit form for the custom type.
  45. */
  46. function ctools_comment_links_content_type_edit_form($form, &$form_state) {
  47. $conf = $form_state['conf'];
  48. $entity = entity_get_info('comment');
  49. $build_mode_options = array();
  50. foreach ($entity['view modes'] as $mode => $option) {
  51. $build_mode_options[$mode] = $option['label'];
  52. }
  53. $form['build_mode'] = array(
  54. '#title' => t('Build mode'),
  55. '#type' => 'select',
  56. '#description' => t('Select a build mode for this comment.'),
  57. '#options' => $build_mode_options,
  58. '#default_value' => $conf['build_mode'],
  59. );
  60. return $form;
  61. }
  62. function ctools_comment_links_content_type_edit_form_submit($form, &$form_state) {
  63. // Copy everything from our defaults.
  64. foreach (array_keys($form_state['plugin']['defaults']) as $key) {
  65. $form_state['conf'][$key] = $form_state['values'][$key];
  66. }
  67. }
  68. function ctools_comment_links_content_type_admin_title($subtype, $conf, $context) {
  69. return t('"@s" links', array('@s' => $context->identifier));
  70. }