Projet

Général

Profil

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

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

1
<?php
2

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

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

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

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

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

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

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

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

    
74
  $breadcrumb = array_merge(drupal_get_breadcrumb(), array_reverse($breadcrumb));
75
  drupal_set_breadcrumb($breadcrumb);
76
}