function i18nviews_plugin_argument_validate_i18n_taxonomy_term::validate_argument in Internationalization Views 6.2
Same name and namespace in other branches
- 6.3 includes/i18nviews_plugin_argument_validate_i18n_taxonomy_term.inc \i18nviews_plugin_argument_validate_i18n_taxonomy_term::validate_argument()
- 7.3 includes/i18nviews_plugin_argument_validate_i18n_taxonomy_term.inc \i18nviews_plugin_argument_validate_i18n_taxonomy_term::validate_argument()
File
- includes/
i18nviews_plugin_argument_validate_i18n_taxonomy_term.inc, line 55 - Contains the 'Taxonomy term (i18n)' argument validator plugin.
Class
- i18nviews_plugin_argument_validate_i18n_taxonomy_term
- Validate whether an argument is a localized term.
Code
function validate_argument($argument) {
global $language;
$langcode = $language->language;
$vids = isset($this->argument->options['validate_argument_vocabulary_i18n']) ? array_filter($this->argument->options['validate_argument_vocabulary_i18n']) : array();
$type = isset($this->argument->options['validate_argument_type_i18n']) ? $this->argument->options['validate_argument_type_i18n'] : 'i18n_name';
$transform = isset($this->argument->options['validate_argument_transform_i18n']) ? $this->argument->options['validate_argument_transform_i18n'] : FALSE;
switch ($type) {
case 'i18n_name':
case 'i18n_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 localised 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 == 'i18n_convert') {
$this->argument->argument = $result->tid;
}
// ToDo: check vocabulary translation mode (if localization needed)
$this->argument->validated_title = check_plain(tt('taxonomy:term:' . $result->tid . ':name', $result->name));
return TRUE;
}
}