| 1 |
<?php
|
| 2 |
// $Id: country_code.views.inc,v 1.13 2008/10/28 20:46:34 nedjo Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Views handling file for country code module.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_views_handlers().
|
| 11 |
*/
|
| 12 |
function country_code_views_handlers() {
|
| 13 |
return array(
|
| 14 |
'handlers' => array(
|
| 15 |
'country_code_handler_field_node_country' => array(
|
| 16 |
'parent' => 'views_handler_field_node',
|
| 17 |
),
|
| 18 |
'country_code_handler_filter_node_country' => array(
|
| 19 |
'parent' => 'views_handler_filter_in_operator',
|
| 20 |
),
|
| 21 |
'country_code_handler_filter_node_country_current' => array(
|
| 22 |
'parent' => 'views_handler_filter',
|
| 23 |
),
|
| 24 |
),
|
| 25 |
);
|
| 26 |
}
|
| 27 |
|
| 28 |
/**
|
| 29 |
* Substitute country code and country language; this works with cached queries.
|
| 30 |
*/
|
| 31 |
function country_code_views_query_substitutions($view) {
|
| 32 |
global $language;
|
| 33 |
return array(
|
| 34 |
'***COUNTRY_CODE***' => country_code(),
|
| 35 |
// Pass a two-digit language, to be used as a fallback.
|
| 36 |
'***COUNTRY_CODE_LANGUAGE***' => substr($language->language, 0, 2),
|
| 37 |
);
|
| 38 |
}
|
| 39 |
|
| 40 |
/**
|
| 41 |
* Implementation of hook_views_data_alter().
|
| 42 |
*
|
| 43 |
* Add country information to the node table.
|
| 44 |
*/
|
| 45 |
function country_code_views_data_alter(&$data) {
|
| 46 |
|
| 47 |
// Only add fields if translation module enabled.
|
| 48 |
if (module_exists('translation')) {
|
| 49 |
// Country field.
|
| 50 |
$data['node']['country_code'] = array(
|
| 51 |
'title' => t('Country'),
|
| 52 |
'help' => t('The country the content is set to.'),
|
| 53 |
'field' => array(
|
| 54 |
'title' => t('Country'),
|
| 55 |
'help' => t('Display the country based on langauge.'),
|
| 56 |
'handler' => 'country_code_handler_field_node_country',
|
| 57 |
),
|
| 58 |
'filter' => array(
|
| 59 |
'field' => 'language',
|
| 60 |
'handler' => 'country_code_handler_filter_node_country',
|
| 61 |
'label' => t('Country'),
|
| 62 |
),
|
| 63 |
);
|
| 64 |
// Current country field.
|
| 65 |
$data['node']['country_code_current'] = array(
|
| 66 |
'title' => t("Current country's language"),
|
| 67 |
'help' => t("Content for the current country language, with a generic language fallback. If the current language is fr-ca for Canadian French, this filter will show content in the fr-ca language or, if there isn't such a translation, a fr version."),
|
| 68 |
'filter' => array(
|
| 69 |
'field' => 'language',
|
| 70 |
'handler' => 'country_code_handler_filter_node_country_current',
|
| 71 |
'label' => t("Current country's language"),
|
| 72 |
),
|
| 73 |
);
|
| 74 |
}
|
| 75 |
|
| 76 |
}
|