term_name.inc 3.1 KB

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