Projet

Général

Profil

Paste
Télécharger (2,27 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / plugins / arguments / terms.inc @ 1e39edcb

1
<?php
2

    
3
/**
4
 * @file
5
 *
6
 * Plugin to provide an argument handler for a Taxonomy term
7
 */
8

    
9
/**
10
 * Plugins are described by creating a $plugin array which will be used
11
 * by the system that includes this file.
12
 */
13
$plugin = array(
14
  'title' => t("Taxonomy term (multiple): ID"),
15
  // keyword to use for %substitution
16
  'keyword' => 'term',
17
  '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.'),
18
  'context' => 'ctools_terms_context',
19
  'default' => array('breadcrumb' => TRUE),
20
  'settings form' => 'ctools_terms_settings_form',
21
  'placeholder form' => array(
22
    '#type' => 'textfield',
23
    '#description' => t('Enter a term ID or a list of term IDs separated by a + or a ,'),
24
  ),
25
  'breadcrumb' => 'ctools_terms_breadcrumb',
26
);
27

    
28
/**
29
 * Discover if this argument gives us the term we crave.
30
 */
31
function ctools_terms_context($arg = NULL, $conf = NULL, $empty = FALSE) {
32
  // If unset it wants a generic, unfilled context.
33
  if ($empty) {
34
    return ctools_context_create_empty('terms');
35
  }
36

    
37
  $terms = ctools_break_phrase($arg);
38
  if (empty($terms->value) || !empty($terms->invalid_input)) {
39
    return FALSE;
40
  }
41

    
42
  $context = ctools_context_create('terms', $terms);
43
  $context->original_argument = $arg;
44
  return $context;
45
}
46

    
47
/**
48
 * Settings form for the argument
49
 */
50
function ctools_terms_settings_form(&$form, &$form_state, $conf) {
51
  $form['settings']['breadcrumb'] = array(
52
    '#title' => t('Inject hierarchy of first term into breadcrumb trail'),
53
    '#type' => 'checkbox',
54
    '#default_value' => !empty($conf['breadcrumb']),
55
    '#description' => t('If checked, taxonomy term parents will appear in the breadcrumb trail.'),
56
  );
57
//  return $form;
58
}
59

    
60
/**
61
 * Inject the breadcrumb trail if necessary.
62
 */
63
function ctools_terms_breadcrumb($conf, $context) {
64
  if (empty($conf['breadcrumb'])) {
65
    return;
66
  }
67

    
68
  $current = new stdClass();
69
  $current->tid = $context->tids[0];
70
  $breadcrumb = array();
71
  while ($parents = taxonomy_get_parents($current->tid)) {
72
    $current = array_shift($parents);
73
    $breadcrumb[] = l($current->name, 'taxonomy/term/' . $current->tid);
74
  }
75

    
76
  $breadcrumb = array_merge(drupal_get_breadcrumb(), array_reverse($breadcrumb));
77
  drupal_set_breadcrumb($breadcrumb);
78
}