comment_links.inc 2.3 KB

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