| 1 |
<?php |
<?php |
| 2 |
// $Id: views_plugin_argument_validate_taxonomy_term.inc,v 1.4.2.1 2009/06/02 18:36:38 merlinofchaos Exp $ |
// $Id: views_plugin_argument_validate_taxonomy_term.inc,v 1.4.2.2 2009/09/15 16:51:59 merlinofchaos Exp $ |
| 3 |
/** |
/** |
| 4 |
* @file |
* @file |
| 5 |
* Contains the 'taxonomy term' argument validator plugin. |
* Contains the 'taxonomy term' argument validator plugin. |
| 9 |
* Validate whether an argument is an acceptable node. |
* Validate whether an argument is an acceptable node. |
| 10 |
*/ |
*/ |
| 11 |
class views_plugin_argument_validate_taxonomy_term extends views_plugin_argument_validate { |
class views_plugin_argument_validate_taxonomy_term extends views_plugin_argument_validate { |
| 12 |
function validate_form(&$form, &$form_state) { |
function option_definition() { |
| 13 |
|
$options = parent::option_definition(); |
| 14 |
|
$options['vids'] = array('default' => array()); |
| 15 |
|
$options['type'] = array('default' => 'tid'); |
| 16 |
|
$options['transform'] = array('default' => FALSE); |
| 17 |
|
|
| 18 |
|
return $options; |
| 19 |
|
} |
| 20 |
|
|
| 21 |
|
function options_form(&$form, &$form_state) { |
| 22 |
$vocabularies = taxonomy_get_vocabularies(); |
$vocabularies = taxonomy_get_vocabularies(); |
| 23 |
$options = array(); |
$options = array(); |
| 24 |
foreach ($vocabularies as $voc) { |
foreach ($vocabularies as $voc) { |
| 25 |
$options[$voc->vid] = check_plain($voc->name); |
$options[$voc->vid] = check_plain($voc->name); |
| 26 |
} |
} |
| 27 |
|
|
| 28 |
$form['validate_argument_vocabulary'] = array( |
$form['vids'] = array( |
| 29 |
'#type' => 'checkboxes', |
'#type' => 'checkboxes', |
|
'#prefix' => '<div id="edit-options-validate-argument-vocabulary-wrapper">', |
|
|
'#suffix' => '</div>', |
|
| 30 |
'#title' => t('Vocabularies'), |
'#title' => t('Vocabularies'), |
| 31 |
'#options' => $options, |
'#options' => $options, |
| 32 |
'#default_value' => isset($this->argument->options['validate_argument_vocabulary']) ? $this->argument->options['validate_argument_vocabulary'] : array(), |
'#default_value' => $this->options['vids'], |
| 33 |
'#description' => t('If you wish to validate for specific vocabularies, check them; if none are checked, all terms will pass.'), |
'#description' => t('If you wish to validate for specific vocabularies, check them; if none are checked, all terms will pass.'), |
|
'#process' => array('expand_checkboxes', 'views_process_dependency'), |
|
|
'#dependency' => array('edit-options-validate-type' => array($this->id)), |
|
| 34 |
); |
); |
| 35 |
|
|
| 36 |
$form['validate_argument_type'] = array( |
$form['type'] = array( |
| 37 |
'#type' => 'select', |
'#type' => 'select', |
| 38 |
'#title' => t('Argument type'), |
'#title' => t('Argument type'), |
| 39 |
'#options' => array( |
'#options' => array( |
| 42 |
'name' => t('Term name or synonym'), |
'name' => t('Term name or synonym'), |
| 43 |
'convert' => t('Term name/synonym converted to Term ID'), |
'convert' => t('Term name/synonym converted to Term ID'), |
| 44 |
), |
), |
| 45 |
'#default_value' => isset($this->argument->options['validate_argument_type']) ? $this->argument->options['validate_argument_type'] : 'tid', |
'#default_value' => $this->options['type'], |
| 46 |
'#description' => t('Select the form of this argument; if using term name, it is generally more efficient to convert it to a term ID and use Taxonomy: Term ID rather than Taxonomy: Term Name" as an argument.'), |
'#description' => t('Select the form of this argument; if using term name, it is generally more efficient to convert it to a term ID and use Taxonomy: Term ID rather than Taxonomy: Term Name" as an argument.'), |
|
'#process' => array('views_process_dependency'), |
|
|
'#dependency' => array('edit-options-validate-type' => array($this->id)), |
|
| 47 |
); |
); |
| 48 |
|
|
| 49 |
$form['validate_argument_transform'] = array( |
$form['transform'] = array( |
| 50 |
'#type' => 'checkbox', |
'#type' => 'checkbox', |
| 51 |
'#title' => t('Transform dashes in URL to spaces in term name arguments'), |
'#title' => t('Transform dashes in URL to spaces in term name arguments'), |
| 52 |
'#default_value' => isset($this->argument->options['validate_argument_transform']) ? $this->argument->options['validate_argument_transform'] : FALSE, |
'#default_value' => $this->options['transform'], |
|
'#process' => array('views_process_dependency'), |
|
|
'#dependency' => array('edit-options-validate-argument-type' => array('convert')), |
|
| 53 |
); |
); |
| 54 |
} |
} |
| 55 |
|
|
| 56 |
|
function options_submit(&$form, &$form_state, &$options) { |
| 57 |
|
// filter trash out of the options so we don't store giant unnecessary arrays |
| 58 |
|
$options['vids'] = array_filter($options['vids']); |
| 59 |
|
} |
| 60 |
|
|
| 61 |
|
function convert_options(&$options) { |
| 62 |
|
if (!isset($options['vids']) && !empty($this->argument->options['validate_argument_vocabulary'])) { |
| 63 |
|
$options['vids'] = $this->argument->options['validate_argument_vocabulary']; |
| 64 |
|
$options['type'] = $this->argument->options['validate_argument_type']; |
| 65 |
|
$options['transform'] = $this->argument->options['validate_argument_transform']; |
| 66 |
|
} |
| 67 |
|
} |
| 68 |
|
|
| 69 |
function validate_argument($argument) { |
function validate_argument($argument) { |
| 70 |
$vids = isset($this->argument->options['validate_argument_vocabulary']) ? array_filter($this->argument->options['validate_argument_vocabulary']) : array(); |
$vids = $this->options['vids']; |
| 71 |
$type = isset($this->argument->options['validate_argument_type']) ? $this->argument->options['validate_argument_type'] : 'tid'; |
$type = $this->options['type']; |
| 72 |
$transform = isset($this->argument->options['validate_argument_transform']) ? $this->argument->options['validate_argument_transform'] : FALSE; |
$transform = $this->options['transform']; |
| 73 |
|
|
| 74 |
switch ($type) { |
switch ($type) { |
| 75 |
case 'tid': |
case 'tid': |
| 81 |
if (!$result) { |
if (!$result) { |
| 82 |
return FALSE; |
return FALSE; |
| 83 |
} |
} |
|
|
|
| 84 |
return empty($vids) || !empty($vids[$result->vid]); |
return empty($vids) || !empty($vids[$result->vid]); |
| 85 |
|
|
| 86 |
case 'tids': |
case 'tids': |
| 87 |
$tids = new stdClass(); |
$tids = new stdClass(); |
| 88 |
$tids->value = $argument; |
$tids->value = $argument; |
| 112 |
$this->argument->validated_title = implode($tids->operator == 'or' ? ' + ' : ', ', $titles); |
$this->argument->validated_title = implode($tids->operator == 'or' ? ' + ' : ', ', $titles); |
| 113 |
// If this is not empty, we did not find a tid. |
// If this is not empty, we did not find a tid. |
| 114 |
return empty($test); |
return empty($test); |
| 115 |
|
|
| 116 |
case 'name': |
case 'name': |
| 117 |
case 'convert': |
case 'convert': |
| 118 |
$and = ''; |
$and = ''; |