'i18n_node', 'join' => array( 'left' => array( 'table' => 'node', 'field' => 'nid' ), 'right' => array( 'field' => 'nid' ) ) ); $tables['i18n']['fields']['language'] = array( 'name' => t('Internationalization: Language'), 'sortable' => true, 'handler' => 'i18n_views_handler_language', ); $tables['i18n']['filters']['language'] = array( 'name' => t('Internationalization: Language'), 'list-type' => 'list', 'value-type' => 'array', 'list' => 'i18n_views_language_list', 'operator' => 'views_handler_operator_or', 'help' => t('Enabled languages for content.'), ); $tables['i18n']['filters']['extlanguage'] = array( 'field' => 'language', 'name' => t('Internationalization: Language (extended)'), 'list-type' => 'list', 'value-type' => 'array', 'list' => 'i18n_views_language_list_all', 'operator' => 'views_handler_operator_or', 'help' => t('All defined languages for content.'), ); $tables['i18n']['filters']['selection'] = array( 'name' => t('Internationalization: Selection'), 'handler' => 'i18n_views_filter_handler', 'list-type' => 'select', 'operator' => array('=' => t('Is')), 'list' => '_i18n_selection_mode', 'help' => t('Content language.'), 'cacheable' => 'no' // This query condition cannot be cached ); return $tables; } function i18n_views_language_list($a, $b){ return locale_language_list(); } function i18n_views_language_list_all($a, $b){ return locale_language_list('name', TRUE); } function i18n_views_handler_language($fieldinfo, $fielddata, $value, $data) { $languages = locale_language_list('name', TRUE); return $languages[$value]; } /** * Filter handler callback. Manages language selection mode */ function i18n_views_filter_handler($filterdata, $filterinfo, &$query) { if ($filterdata == 'handler' && $filterinfo['field'] == 'i18n.selection' && $mode = $filterinfo['value']) { // If this filter is used, rollback value set in pre_query and set the new one. i18n_selection_mode('reset'); i18n_selection_mode($mode); } } /** * Implementation of hook_views_pre_query(). * * Disable language conditions for views. This is called before filter handlers */ function i18n_views_pre_query(&$view) { // If any language filter, the language selection mode will be 'off' foreach($view->exposed_filter as $filter) { if($filter['field'] == 'i18n.language') { i18n_selection_mode('off'); return; } } // If no filter, sets the one from settings for this view i18n_selection_mode(variable_get('i18n_selection_mode', 'simple')); } /** * Implementation of hook_views_pre_view(). * * If used language selection filter, reset query rewriting again */ function i18n_views_pre_view(&$view, &$items) { i18n_selection_mode('reset'); } /** * Implementation of hook_form_alter() * * @ TODO Copied from i18ntaxonomy, update all this */ function i18nviews_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'views_filters' && $translate = variable_get('i18ntaxonomy_vocabularies', array())) { // We only translate exposed filters here $view = $form['view']['#value']; if($view->exposed_filter) { foreach($view->exposed_filter as $index => $filter) { $matches = array(); if($filter['field'] == 'term_node.tid') { // That's a full taxonomy box. Translate options: arary(tid => "Vocabulary: Term") // First, we get a translated list. Then we replace on the options array $replace = _i18ntaxonomy_vocabulary_terms(array_keys($translate)); foreach($replace as $tid => $name) { if(isset($form["filter$index"]['#options'][$tid])) { $form["filter$index"]['#options'][$tid] = $name; } } } elseif(preg_match("/term_node_(\d+)\.tid/", $filter['field'], $matches)) { $vid = $matches[1]; if ($translate[$vid]) { // Translate this vocabulary terms, field name is filter$index vid = $matches[1] foreach ($form["filter$index"]['#options'] as $value => $option) { if ($value != '**ALL**') { // ALL option should be already localized // This may be an object with an option property being an array (tid => name) if (is_object($option) && is_array($option->option)) { foreach (array_keys($option->option) as $tid) { $option->option[$tid] = t($option->option[$tid]); } $form["filter$index"]['#options'][$value] = $option; // But it used to be a plain string, so let's keep this just in case... } elseif(is_string($option)) { $form["filter$index"]['#options'][$value] = t($option); } } } } } } } } }