diff --git a/i18nviews.info b/i18nviews.info index a95188a..dd6162a 100644 --- a/i18nviews.info +++ b/i18nviews.info @@ -27,5 +27,6 @@ files[] = includes/i18nviews_handler_filter_taxonomy_index_tid.inc files[] = includes/i18nviews_handler_filter_taxonomy_term_name.inc files[] = includes/i18nviews_handler_filter_taxonomy_term_language.inc files[] = includes/i18nviews_handler_filter_term_node_tid_depth.inc +files[] = includes/i18nviews_handler_sort_taxonomy_term_name.inc files[] = includes/i18nviews_plugin_argument_validate_i18n_taxonomy_term.inc files[] = includes/i18nviews_plugin_localization_i18nstrings.inc diff --git a/includes/i18nviews.views.inc b/includes/i18nviews.views.inc index a8e2e6b..3bcc842 100644 --- a/includes/i18nviews.views.inc +++ b/includes/i18nviews.views.inc @@ -68,13 +68,10 @@ function i18nviews_views_data_alter_i18n_taxonomy(&$data) { // name_i18n is not a real field in the database but we could actually let's just add the name, that's we need too. 'real field' => 'name', ), - // TODO currently almost impossible, JOIN to i18n_string table needed - /* 'sort' => array( //'handler' => 'views_handler_sort', 'handler' => 'i18nviews_handler_sort_taxonomy_term_name', ), - */ 'filter' => array( //'handler => 'views_handler_filter_string', 'handler' => 'i18nviews_handler_filter_taxonomy_term_name', diff --git a/includes/i18nviews_handler_sort_taxonomy_term_name.inc b/includes/i18nviews_handler_sort_taxonomy_term_name.inc new file mode 100644 index 0000000..595b386 --- /dev/null +++ b/includes/i18nviews_handler_sort_taxonomy_term_name.inc @@ -0,0 +1,65 @@ +language; + $this->ensure_my_table(); + + // Use alias if available (for sort using relationships). + $left_table = empty($this->table_alias) ? $this->table : $this->table_alias; + + // Join with i18n_string table. + $i18n_string_join = new views_join(); + $i18n_string_join->table = 'i18n_string'; + $i18n_string_join->left_table = $left_table; + $i18n_string_join->left_field = 'tid'; + $i18n_string_join->field = 'objectid'; + $i18n_string_join->type = 'LEFT'; + $i18n_string_join->extra_type = 'AND'; + $i18n_string_join->extra = array( + array( + 'field' => 'textgroup', + 'value' => 'taxonomy', + ), + array( + 'field' => 'type', + 'value' => 'term', + ), + array( + 'field' => 'property', + 'value' => 'name', + ), + ); + $i18n_string = $this->query->add_relationship('term_i18n_string', $i18n_string_join, $left_table); + + // Join with locales_target to get translated value. + $locales_target_join = new views_join(); + $locales_target_join->table = 'locales_target'; + $locales_target_join->left_table = $i18n_string; + $locales_target_join->left_field = 'lid'; + $locales_target_join->field = 'lid'; + $locales_target_join->type = 'LEFT'; + $locales_target_join->extra = array( + array( + 'field' => 'language', + 'value' => $langcode, + ), + ); + $locales_target = $this->query->add_relationship('term_i18n_string_translation', $locales_target_join, $i18n_string); + + // Order by translated value. + $this->query->add_orderby($locales_target, 'translation', $this->options['order']); + } +}