| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: term.inc,v 1.6.2.4 2010/07/05 19:22:35 merlinofchaos Exp $ 3 4 /** 5 * @file 6 * 7 * Plugin to provide an argument handler for a Taxonomy term 8 */ 9 10 /** 11 * Plugins are described by creating a $plugin array which will be used 12 * by the system that includes this file. 13 */ 14 $plugin = array( 15 'title' => t("Taxonomy term: ID"), 16 // keyword to use for %substitution 17 'keyword' => 'term', 18 'description' => t('Creates a single taxonomy term from a taxonomy ID or taxonomy term name.'), 19 'context' => 'ctools_term_context', 20 'default' => array('input_form' => 'tid', 'breadcrumb' => TRUE), 21 'settings form' => 'ctools_term_settings_form', 22 'placeholder form' => 'ctools_term_ctools_argument_placeholder', 23 'breadcrumb' => 'ctools_term_breadcrumb', 24 ); 25 26 /** 27 * Discover if this argument gives us the term we crave. 28 */ 29 function ctools_term_context($arg = NULL, $conf = NULL, $empty = FALSE) { 30 // If unset it wants a generic, unfilled context. 31 if ($empty) { 32 return ctools_context_create_empty('term'); 33 } 34 35 switch ($conf['input_form']) { 36 case 'tid': 37 default: 38 if (!is_numeric($arg)) { 39 return FALSE; 40 } 41 $term = taxonomy_get_term($arg); 42 break; 43 44 case 'term': 45 $terms = taxonomy_get_term_by_name($arg); 46 47 $conf['vids'] = is_array($conf['vids']) ? array_filter($conf['vids']) : NULL; 48 if ((count($terms) > 1) && isset($conf['vids'])) { 49 foreach ($terms as $potential) { 50 foreach ($conf['vids'] as $vid => $active) { 51 if ($active && $potential->vid == $vid) { 52 $term = $potential; 53 // break out of the foreaches AND the case 54 break 3; 55 } 56 } 57 } 58 } 59 $term = array_shift($terms); 60 break; 61 } 62 63 if (empty($term)) { 64 return NULL; 65 } 66 67 if (!empty($conf['vids']) && array_filter($conf['vids']) && empty($conf['vids'][$term->vid])) { 68 return NULL; 69 } 70 71 $context = ctools_context_create('term', $term); 72 $context->original_argument = $arg; 73 return $context; 74 } 75 76 /** 77 * Settings form for the argument 78 */ 79 function ctools_term_settings_form(&$form, &$form_state, $conf) { 80 // @todo allow synonym use like Views does. 81 $form['settings']['input_form'] = array( 82 '#title' => t('Argument type'), 83 '#type' => 'radios', 84 '#options' => array('tid' => t('Term ID'), 'term' => t('Term name')), 85 '#default_value' => $conf['input_form'], 86 '#prefix' => '<div class="clear-block">', 87 '#suffix' => '</div>', 88 ); 89 90 $vocabularies = taxonomy_get_vocabularies(); 91 $options = array(); 92 foreach ($vocabularies as $vid => $vocab) { 93 $options[$vid] = $vocab->name; 94 } 95 $form['settings']['vids'] = array( 96 '#title' => t('Limit to these vocabularies'), 97 '#type' => 'checkboxes', 98 '#options' => $options, 99 '#default_value' => !empty($conf['vids']) ? $conf['vids'] : array(), 100 '#description' => t('If no vocabularies are checked, terms from all vocabularies will be accepted.'), 101 ); 102 103 $form['settings']['breadcrumb'] = array( 104 '#title' => t('Inject hierarchy into breadcrumb trail'), 105 '#type' => 'checkbox', 106 '#default_value' => !empty($conf['breadcrumb']), 107 '#description' => t('If checked, taxonomy term parents will appear in the breadcrumb trail.'), 108 ); 109 } 110 111 /** 112 * Form fragment to get an argument to convert a placeholder for preview. 113 */ 114 function ctools_term_ctools_argument_placeholder($conf) { 115 switch ($conf['input_form']) { 116 case 'tid': 117 default: 118 return array( 119 '#type' => 'textfield', 120 '#description' => t('Enter a taxonomy term ID.'), 121 ); 122 case 'term': 123 return array( 124 '#type' => 'textfield', 125 '#description' => t('Enter a taxonomy term name.'), 126 ); 127 } 128 } 129 130 /** 131 * Inject the breadcrumb trail if necessary. 132 */ 133 function ctools_term_breadcrumb($conf, $context) { 134 if (empty($conf['breadcrumb'])) { 135 return; 136 } 137 138 $breadcrumb = array(); 139 $current->tid = $context->data->tid; 140 while ($parents = taxonomy_get_parents($current->tid)) { 141 $current = array_shift($parents); 142 $breadcrumb[] = l($current->name, 'taxonomy/term/' . $current->tid); 143 } 144 145 $breadcrumb = array_merge(drupal_get_breadcrumb(), array_reverse($breadcrumb)); 146 drupal_set_breadcrumb($breadcrumb); 147 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |