node_links.inc 3.0 KB

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