terms.inc 2.3 KB

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