Created
September 11, 2012 18:00
-
-
Save EclipseGc/3700318 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function my_module_query_views_alter($query) { | |
$view = $query->alterMetaData['view']; | |
if ($view->name == 'product_term_menus' && $view->current_display == 'panel_pane_1') { | |
$fields = $query->getFields(); | |
$tables = $query->getTables(); | |
$tid_alias = $fields['tid']['alias']; | |
$name_alias = $fields['taxonomy_term_data_name']['alias']; | |
$term_table_alias = $tables['taxonomy_term_data']['alias']; | |
// Join on locales tables to get available translations. | |
$query->leftJoin('locales_source', 'ls', "ls.location = CONCAT('taxonomy:term:', " . $term_table_alias . '.' . $tid_alias . ", ':name')"); | |
$query->leftJoin('locales_target', 'lt', 'lt.lid = ls.lid AND lt.language = :language', array(':language' => $GLOBALS['language']->language)); | |
// Conditionally use translation or source value. | |
$query->addExpression('COALESCE(lt.translation, ' . $term_table_alias . '.' . $name_alias .')', $name_alias); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment