node_links.inc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 links'),
  10. 'icon' => 'icon_node.png',
  11. 'description' => t('Node links of the referenced node.'),
  12. 'required context' => new ctools_context_required(t('Node'), 'node'),
  13. 'category' => t('Node'),
  14. 'defaults' => array(
  15. 'override_title' => FALSE,
  16. 'override_title_text' => '',
  17. 'build_mode' => '',
  18. 'identifier' => '',
  19. 'link' => TRUE,
  20. ),
  21. );
  22. /**
  23. * Output function for the 'node' content type. Outputs a node
  24. * based on the module and delta supplied in the configuration.
  25. */
  26. function ctools_node_links_content_type_render($subtype, $conf, $panel_args, $context) {
  27. if (!empty($context) && empty($context->data)) {
  28. return;
  29. }
  30. $node = isset($context->data) ? clone $context->data : NULL;
  31. $block = new stdClass();
  32. $block->module = 'node';
  33. $block->delta = $node->nid;
  34. if (empty($node)) {
  35. $block->delta = 'placeholder';
  36. $block->subject = t('Node title.');
  37. $block->content = t('Node links go here.');
  38. }
  39. else {
  40. if (!empty($conf['identifier'])) {
  41. $node->panel_identifier = $conf['identifier'];
  42. }
  43. $block->subject = $node->title;
  44. node_build_content($node, $conf['build_mode']);
  45. $block->content = $node->content['links'];
  46. }
  47. if (!empty($conf['link']) && $node) {
  48. $block->title_link = "node/$node->nid";
  49. }
  50. return $block;
  51. }
  52. /**
  53. * Returns an edit form for the custom type.
  54. */
  55. function ctools_node_links_content_type_edit_form($form, &$form_state) {
  56. $conf = $form_state['conf'];
  57. $form['link'] = array(
  58. '#title' => t('Link title to node'),
  59. '#type' => 'checkbox',
  60. '#default_value' => $conf['link'],
  61. '#description' => t('Check here to make the title link to the node.'),
  62. );
  63. $entity = entity_get_info('node');
  64. $build_mode_options = array();
  65. foreach ($entity['view modes'] as $mode => $option) {
  66. $build_mode_options[$mode] = $option['label'];
  67. }
  68. $form['build_mode'] = array(
  69. '#title' => t('Build mode'),
  70. '#type' => 'select',
  71. '#description' => t('Select a build mode for this node.'),
  72. '#options' => $build_mode_options,
  73. '#default_value' => $conf['build_mode'],
  74. );
  75. $form['identifier'] = array(
  76. '#type' => 'textfield',
  77. '#default_value' => $conf['identifier'],
  78. '#title' => t('Identifier'),
  79. '#description' => t('Whatever is placed here will appear in @identifier, to help theme node links displayed on the panel', array('@identifier' => $node->panel_identifier)),
  80. );
  81. return $form;
  82. }
  83. function ctools_node_links_content_type_edit_form_submit($form, &$form_state) {
  84. // Copy everything from our defaults.
  85. foreach (array_keys($form_state['plugin']['defaults']) as $key) {
  86. $form_state['conf'][$key] = $form_state['values'][$key];
  87. }
  88. }
  89. function ctools_node_links_content_type_admin_title($subtype, $conf, $context) {
  90. return t('"@s" links', array('@s' => $context->identifier));
  91. }