diff --git includes/i18nviews.views.inc includes/i18nviews.views.inc index f7982f5..2060e2b 100644 --- includes/i18nviews.views.inc +++ includes/i18nviews.views.inc @@ -71,5 +71,14 @@ function i18nviews_views_plugins() { 'path' => $path, ), ), + 'argument validator' => array( + 'i18n_taxonomy_term' => array( + 'title' => t('Taxonomy term (i18n)'), + 'help' => t("Use the locale to interpret arguments."), + 'handler' => 'views_plugin_argument_validate_i18n_taxonomy_term', + 'path' => $path, + 'parent' => 'taxonomy_term', + ), + ), ); } diff --git includes/i18nviews.views.inc.orig includes/i18nviews.views.inc.orig new file mode 100644 index 0000000..f7982f5 --- /dev/null +++ includes/i18nviews.views.inc.orig @@ -0,0 +1,75 @@ + t('Node translation'), + 'title' => t('Content negotiation'), + 'help' => t('Removes the nodes that are not valid according to the content selection mode.'), + 'filter' => array( + 'handler' => 'content_negotiation_filter_handler', + ), + ); + return $data; +} + +/** + * Implementation of hook_views_handlers + */ +function i18nviews_views_handlers() { + return array( + 'info' => array( + 'path' => drupal_get_path('module', 'i18nviews') . '/includes', + ), + 'handlers' => array( + 'content_negotiation_filter_handler' => array( + 'parent' => 'views_handler_filter', + 'file' => 'includes/content_negotiation_filter_handler.inc' + ), + 'i18nviews_handler_field_taxonomy' => array( + 'parent' => 'views_handler_field_taxonomy', + ), + 'i18nviews_handler_field_term_description' => array( + 'parent' => 'views_handler_field_markup', + ), + 'i18nviews_handler_field_term_node_tid' => array( + 'parent' => 'views_handler_field_term_node_tid', + ), + 'i18nviews_handler_argument_term_node_tid' => array( + 'parent' => 'views_handler_argument_term_node_tid', + ), + 'i18nviews_handler_filter_term_node_tid' => array( + 'parent' => 'views_handler_filter_term_node_tid', + ), + ), + ); +} + + +/** + * Implemenation of hook_views_data_alter(). + */ +function i18nviews_views_data_alter(&$data) { + $data['term_data']['name']['field']['handler'] = 'i18nviews_handler_field_taxonomy'; + $data['term_data']['description']['field']['handler'] = 'i18nviews_handler_field_term_description'; + $data['term_node']['tid']['field']['handler'] = 'i18nviews_handler_field_term_node_tid'; + $data['term_node']['tid']['argument']['handler'] = 'i18nviews_handler_argument_term_node_tid'; + $data['term_node']['tid']['filter']['handler'] = 'i18nviews_handler_filter_term_node_tid'; +} + +/** + * Implementation of hook_views_plugins(). + */ +function i18nviews_views_plugins() { + $path = drupal_get_path('module', 'i18nviews') . '/includes'; + return array( + 'module' => 'i18nviews', + 'localization' => array( + 'i18nstrings' => array( + 'title' => t('Views translation module'), + 'help' => t("Use the locale system as implemented by the Views translation module."), + 'handler' => 'views_plugin_localization_i18nstrings', + 'path' => $path, + ), + ), + ); +} diff --git includes/views_plugin_argument_validate_i18n_taxonomy_term.inc includes/views_plugin_argument_validate_i18n_taxonomy_term.inc new file mode 100644 index 0000000..cabc5fe --- /dev/null +++ includes/views_plugin_argument_validate_i18n_taxonomy_term.inc @@ -0,0 +1,86 @@ +argument->options['validate_argument_vocabulary_i18n'])) { + $options['vids'] = $this->argument->options['validate_argument_vocabulary_i18n']; + $options['type'] = $this->argument->options['validate_argument_type_i18n']; + $options['transform'] = $this->argument->options['validate_argument_transform_i18n']; + } + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $vocabularies = taxonomy_get_vocabularies(); + $options = array(); + // Get the localized vocabularies. + $localisedvocabs = variable_get('i18ntaxonomy_vocabulary', array()); + // Only add the localized vocabularies as options. + foreach ($localisedvocabs as $localisedvocab => $localisedtype) { + if ($localisedtype =='1') { + $options[$localisedvocab] = check_plain($vocabularies[$localisedvocab]->name); + } + } + $form['vids']['#description'] = t('Limit this validator to vocabularies that have been localized'); + $form['vids']['#options'] = $options; + + $form['type']['#options'] = array( + 'i18n_name' => t('Localised Term name or synonym'), + 'i18n_convert' => t('Localised Term name/synonym converted to Term ID'), + ); + $form['type']['#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.'), + } + + function validate_argument($argument) { + global $language; + $langcode =$language->language; + $vids = $this->options['vids']; + $type = $this->options['type']; + $transform = $this->options['transform']; + 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; + } + } +}