node_title.inc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 title'),
  10. 'icon' => 'icon_node.png',
  11. 'description' => t('The title of the referenced node.'),
  12. 'required context' => new ctools_context_required(t('Node'), 'node'),
  13. 'category' => t('Node'),
  14. 'defaults' => array(
  15. 'link' => TRUE,
  16. 'markup' => 'none',
  17. 'id' => '',
  18. 'class' => '',
  19. ),
  20. );
  21. /**
  22. * Render the custom content type.
  23. */
  24. function ctools_node_title_content_type_render($subtype, $conf, $panel_args, $context) {
  25. if (!empty($context) && (empty($context->data) || empty($context->data->nid))) {
  26. return;
  27. }
  28. // Get a shortcut to the node.
  29. $node = $context->data;
  30. // Load information about the node type.
  31. $type = node_type_get_type($node);
  32. // Generate the title.
  33. $content = !empty($conf['link']) ? l($node->title, 'node/' . $node->nid) : check_plain($node->title);
  34. // Build any surrounding markup if so configured.
  35. if (isset($conf['markup']) && $conf['markup'] != 'none') {
  36. $markup = '<' . $conf['markup'];
  37. if (!empty($conf['id'])) {
  38. $markup .= ' id="' . $conf['id'] . '"';
  39. }
  40. if (!empty($conf['class'])) {
  41. $markup .= ' class="' . $conf['class'] . '"';
  42. }
  43. $markup .= '>' . $content . '</' . $conf['markup'] . '>' . "\n";
  44. $content = $markup;
  45. }
  46. // Build the content type block.
  47. $block = new stdClass();
  48. $block->module = 'node_title';
  49. $block->title = $type->title_label;
  50. $block->content = $content;
  51. $block->delta = $node->nid;
  52. return $block;
  53. }
  54. /**
  55. * Returns an edit form for custom type settings.
  56. */
  57. function ctools_node_title_content_type_edit_form($form, &$form_state) {
  58. $conf = $form_state['conf'];
  59. $form['markup'] = array(
  60. '#title' => t('Title tag'),
  61. '#type' => 'select',
  62. '#options' => array(
  63. 'none' => t('- No tag -'),
  64. 'h1' => t('h1'),
  65. 'h2' => t('h2'),
  66. 'h3' => t('h3'),
  67. 'h4' => t('h4'),
  68. 'h5' => t('h5'),
  69. 'h6' => t('h6'),
  70. 'div' => t('div'),
  71. ),
  72. '#default_value' => $conf['markup'],
  73. );
  74. $form['id'] = array(
  75. '#title' => t('CSS id to use'),
  76. '#type' => 'textfield',
  77. '#default_value' => $conf['id'],
  78. );
  79. $form['class'] = array(
  80. '#title' => t('CSS class to use'),
  81. '#type' => 'textfield',
  82. '#default_value' => $conf['class'],
  83. );
  84. $form['link'] = array(
  85. '#title' => t('Link to node'),
  86. '#type' => 'checkbox',
  87. '#default_value' => $conf['link'],
  88. '#description' => t('Check here to make the title link to the node.'),
  89. );
  90. return $form;
  91. }
  92. /**
  93. * Submit handler for the custom type settings form.
  94. */
  95. function ctools_node_title_content_type_edit_form_submit($form, &$form_state) {
  96. // Copy everything from our defaults.
  97. foreach (array_keys($form_state['plugin']['defaults']) as $key) {
  98. $form_state['conf'][$key] = $form_state['values'][$key];
  99. }
  100. }
  101. /**
  102. * Returns the administrative title for a type.
  103. */
  104. function ctools_node_title_content_type_admin_title($subtype, $conf, $context) {
  105. return t('"@s" title', array('@s' => $context->identifier));
  106. }