Projet

Général

Profil

Paste
Télécharger (4,36 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / i18n / i18n_taxonomy / i18n_taxonomy.pages.inc @ 76df55b7

1
<?php
2

    
3
/**
4
 * @file
5
 * Page callbacks for the taxonomy module, i18n remake.
6
 */
7

    
8
/**
9
 * Menu callback; displays all nodes associated with a term.
10
 *
11
 * @param $term
12
 *   The taxonomy term.
13
 * @return
14
 *   The page content.
15
 */
16
function i18n_taxonomy_term_page($term) {
17
  $term = i18n_taxonomy_localize_terms($term);
18

    
19
  // Assign the term name as the page title.
20
  drupal_set_title($term->name);
21

    
22
  // Build breadcrumb based on the hierarchy of the term.
23
  $current = (object) array(
24
    'tid' => $term->tid,
25
  );
26
  // @todo This overrides any other possible breadcrumb and is a pure hard-coded
27
  //   presumption. Make this behavior configurable per vocabulary or term.
28
  $breadcrumb = array();
29
  while ($parents = taxonomy_get_parents($current->tid)) {
30
    $parents = i18n_taxonomy_localize_terms($parents);
31
    $current = array_shift($parents);
32
    $breadcrumb[] = l($current->name, 'taxonomy/term/' . $current->tid);
33
  }
34
  $breadcrumb[] = l(t('Home'), NULL);
35
  $breadcrumb = array_reverse($breadcrumb);
36
  drupal_set_breadcrumb($breadcrumb);
37
  drupal_add_feed('taxonomy/term/' . $term->tid . '/feed', 'RSS - ' . $term->name);
38

    
39
  $build = array();
40

    
41
  $build['term_heading'] = array(
42
    '#prefix' => '<div class="term-listing-heading">',
43
    '#suffix' => '</div>',
44
    'term' => taxonomy_term_view($term, 'full'),
45
  );
46

    
47
  if ($nids = taxonomy_select_nodes($term->tid, TRUE, variable_get('default_nodes_main', 10))) {
48
    $nodes = node_load_multiple($nids);
49
    $build += node_view_multiple($nodes);
50
    $build['pager'] = array(
51
      '#theme' => 'pager',
52
      '#weight' => 5,
53
    );
54
  }
55
  else {
56
    $build['no_content'] = array(
57
      '#prefix' => '<p>',
58
      '#markup' => t('There is currently no content classified with this term.'),
59
      '#suffix' => '</p>',
60
    );
61
  }
62
  return $build;
63
}
64

    
65
/**
66
 * Helper function for autocompletion. Replacement for taxonomy_autocomplete
67
 */
68
function i18n_taxonomy_autocomplete_field($field_name, $tags_typed = '') {
69
  // Part of the criteria for the query come from the field's own settings.
70
  $field = field_info_field($field_name);
71
  $vids = array();
72
  $vocabularies = taxonomy_vocabulary_get_names();
73
  foreach ($field['settings']['allowed_values'] as $tree) {
74
    $vids[] = $vocabularies[$tree['vocabulary']]->vid;
75
  }
76
  // This has been redirected from taxonomy module so we add current language and no language
77
  // Because some of the vocabularies may not have language
78
  $langcode = array(i18n_langcode(), LANGUAGE_NONE);
79
  return _i18n_taxonomy_autocomplete($langcode, $vids, $tags_typed);
80
}
81

    
82
/**
83
 * Helper function for autocompletion. Select by language
84
 */
85
function i18n_taxonomy_autocomplete_language($langcode, $vocabulary, $tags_typed = '') {
86
  $vids = $vocabulary ? array($vocabulary->vid) : NULL;
87
  return _i18n_taxonomy_autocomplete($langcode, $vids, $tags_typed);
88
}
89

    
90
/**
91
 * Helper function for autocompletion
92
 */
93
function _i18n_taxonomy_autocomplete($langcode, $vids, $tags_typed = '') {
94
  // The user enters a comma-separated list of tags. We only autocomplete the last tag.
95
  $tags_typed = drupal_explode_tags($tags_typed);
96
  $tag_last = drupal_strtolower(array_pop($tags_typed));
97

    
98
  $matches = array();
99
  if ($langcode && $tag_last != '') {
100
    $query = db_select('taxonomy_term_data', 't')
101
      ->fields('t', array('tid', 'name'));
102
    $query->addTag('translatable');
103
    $query->addTag('term_access');
104
    // Disable i18n_select for this query
105
    $query->addTag('i18n_select');
106
    // Add language condition
107
    $query->condition('t.language', $langcode);
108

    
109
    // Do not select already entered terms.
110
    if (!empty($tags_typed)) {
111
      $query->condition('t.name', $tags_typed, 'NOT IN');
112
    }
113
    // There may be vocabulary restrictions
114
    if ($vids) {
115
      $query->condition('t.vid', $vids);
116
    }
117
    // Select rows that match by term name.
118
    $tags_return = $query
119
      ->condition('t.name', '%' . db_like($tag_last) . '%', 'LIKE')
120
      ->range(0, 10)
121
      ->execute()
122
      ->fetchAllKeyed();
123

    
124
    $prefix = count($tags_typed) ? drupal_implode_tags($tags_typed) . ', ' : '';
125

    
126
    $term_matches = array();
127
    foreach ($tags_return as $tid => $name) {
128
      $n = $name;
129
      // Term names containing commas or quotes must be wrapped in quotes.
130
      if (strpos($name, ',') !== FALSE || strpos($name, '"') !== FALSE) {
131
        $n = '"' . str_replace('"', '""', $name) . '"';
132
      }
133
      $term_matches[$prefix . $n] = check_plain($name);
134
    }
135
  }
136

    
137
  drupal_json_output($term_matches);
138
}