Index: includes/i18nviews.views.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/i18nviews/includes/i18nviews.views.inc,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 i18nviews.views.inc
--- includes/i18nviews.views.inc 14 Jun 2010 03:15:07 -0000 1.1.2.1
+++ includes/i18nviews.views.inc 18 Nov 2010 16:46:08 -0000
@@ -74,5 +74,14 @@
'path' => $path,
),
),
+ 'argument validator' => array(
+ 'i18_taxonomy_term' => array(
+ 'title' => t('Localised Taxonomy term validator'),
+ 'help' => t("Use the locale to interpret arguments."),
+ 'handler' => 'views_plugin_argument_validate_i18_taxonomy_term',
+ 'path' => $path,
+ 'parent' => 'taxonomy_term',
+ ),
+ ),
);
}
Index: includes/views_plugin_argument_validate_i18_taxonomy_term.inc
===================================================================
RCS file: includes/views_plugin_argument_validate_i18_taxonomy_term.inc
diff -N includes/views_plugin_argument_validate_i18_taxonomy_term.inc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ includes/views_plugin_argument_validate_i18_taxonomy_term.inc 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,89 @@
+vid] = check_plain($voc->name);
+ }
+ $form['validate_argument_vocabulary_i18'] = array(
+ '#type' => 'checkboxes',
+ '#prefix' => '
',
+ '#suffix' => '
',
+ '#title' => t('Vocabularies'),
+ '#options' => $options,
+ '#default_value' => isset($this->argument->options['validate_argument_vocabulary']) ? $this->argument->options['validate_argument_vocabulary'] : array(),
+ '#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)),
+ );
+ $form['validate_argument_type_i18'] = array(
+ '#type' => 'select',
+ '#title' => t('Argument type'),
+ '#options' => array(
+ 'i18_name' => t('Localised Term name or synonym'),
+ 'i18_convert' => t('Localised Term name/synonym converted to Term ID'),
+ ),
+ '#default_value' => isset($this->argument->options['i18_validate_argument_type']) ? $this->argument->options['i18_validate_argument_type'] : 'i18_name',
+ '#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)),
+ );
+ $form['validate_argument_transform_i18'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Transform dashes in URL to spaces in term name arguments'),
+ '#default_value' => isset($this->argument->options['validate_argument_transform']) ? $this->argument->options['validate_argument_transform'] : FALSE,
+ '#process' => array('views_process_dependency'),
+ '#dependency' => array('edit-options-validate-argument-type' => array('convert')),
+ );
+ }
+
+function validate_argument($argument) {
+ global $language;
+ $langcode =$language->language;
+ $vids = isset($this->argument->options['validate_argument_vocabulary_i18']) ? array_filter($this->argument->options['validate_argument_vocabulary_i18']) : array();
+ $type = isset($this->argument->options['validate_argument_type_i18']) ? $this->argument->options['validate_argument_type_i18'] : 'i18_name';
+ $transform = isset($this->argument->options['validate_argument_transform_i18']) ? $this->argument->options['validate_argument_transform_i18'] : FALSE;
+ switch ($type) {
+ case 'i18_name':
+ case 'i18_convert':
+ //Check to see if the term is in fact localised
+ $localised =db_fetch_object(db_query("SELECT source FROM {locales_source} ls INNER JOIN {locales_target} lt ON ( ls.lid = lt.lid AND lt.translation = '%s' AND lt.language= '%s' AND ls.textgroup='taxonomy' )", $argument, $langcode));
+ if (!empty($localised)) {
+ //If it is I set the $argument to the orginal and tell the view that the argument has been localized and to use the source
+ $argument = $localised ->source;
+ $this->argument->argument = $localised ->source;
+ }
+ $and = '';
+ if (!empty($vids)) {
+ $and = " AND td.vid IN(" . implode(', ', $vids) . ')';
+ }
+ if ($transform) {
+ $result = db_fetch_object(db_query("SELECT td.* FROM {term_data} td LEFT JOIN {term_synonym} ts ON ts.tid = td.tid WHERE (replace(td.name, ' ', '-') = '%s' OR replace(ts.name, ' ', '-') = '%s')$and", $argument, $argument));
+ }
+ else {
+ $result = db_fetch_object(db_query("SELECT td.* FROM {term_data} td LEFT JOIN {term_synonym} ts ON ts.tid = td.tid WHERE (td.name = '%s' OR ts.name = '%s')$and", $argument, $argument));
+ }
+ if (!$result) {
+ return FALSE;
+ }
+ if ($type == 'i18_convert') {
+ $this->argument->argument = $result->tid;
+ $this->argument->validated_title = check_plain($result->name);
+ }
+ return TRUE;
+
+ }
+ }
+ }