terms.inc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * @file
  4. *
  5. * Plugin to provide an argument handler for a Taxonomy term
  6. */
  7. /**
  8. * Plugins are described by creating a $plugin array which will be used
  9. * by the system that includes this file.
  10. */
  11. $plugin = array(
  12. 'title' => t("Taxonomy term (multiple): ID"),
  13. // keyword to use for %substitution
  14. 'keyword' => 'term',
  15. 'description' => t('Creates a group of taxonomy terms from a list of tids separated by a comma or a plus sign. In general the first term of the list will be used for panes.'),
  16. 'context' => 'ctools_terms_context',
  17. 'default' => array('breadcrumb' => TRUE),
  18. 'settings form' => 'ctools_terms_settings_form',
  19. 'placeholder form' => array(
  20. '#type' => 'textfield',
  21. '#description' => t('Enter a term ID or a list of term IDs separated by a + or a ,'),
  22. ),
  23. 'breadcrumb' => 'ctools_terms_breadcrumb',
  24. );
  25. /**
  26. * Discover if this argument gives us the term we crave.
  27. */
  28. function ctools_terms_context($arg = NULL, $conf = NULL, $empty = FALSE) {
  29. // If unset it wants a generic, unfilled context.
  30. if ($empty) {
  31. return ctools_context_create_empty('terms');
  32. }
  33. $terms = ctools_break_phrase($arg);
  34. if (empty($terms->value) || !empty($terms->invalid_input)) {
  35. return FALSE;
  36. }
  37. $context = ctools_context_create('terms', $terms);
  38. $context->original_argument = $arg;
  39. return $context;
  40. }
  41. /**
  42. * Settings form for the argument
  43. */
  44. function ctools_terms_settings_form(&$form, &$form_state, $conf) {
  45. $form['settings']['breadcrumb'] = array(
  46. '#title' => t('Inject hierarchy of first term into breadcrumb trail'),
  47. '#type' => 'checkbox',
  48. '#default_value' => !empty($conf['breadcrumb']),
  49. '#description' => t('If checked, taxonomy term parents will appear in the breadcrumb trail.'),
  50. );
  51. // return $form;
  52. }
  53. /**
  54. * Inject the breadcrumb trail if necessary.
  55. */
  56. function ctools_terms_breadcrumb($conf, $context) {
  57. if (empty($conf['breadcrumb'])) {
  58. return;
  59. }
  60. $current = new stdClass();
  61. $current->tid = $context->tids[0];
  62. $breadcrumb = array();
  63. while ($parents = taxonomy_get_parents($current->tid)) {
  64. $current = array_shift($parents);
  65. $breadcrumb[] = l($current->name, 'taxonomy/term/' . $current->tid);
  66. }
  67. $breadcrumb = array_merge(drupal_get_breadcrumb(), array_reverse($breadcrumb));
  68. drupal_set_breadcrumb($breadcrumb);
  69. }