Language filter support
naxoc - January 29, 2009 - 15:49
| Project: | Content Management Filter |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | task |
| Priority: | normal |
| Assigned: | naxoc |
| Status: | closed |
| Issue tags: | i18n, languages |
Jump to:
Description
I needed to be able to filter the language of the nodes, so I wrote this patch. It works fine for me, but give it a test. You need to have more than one language enabled to be able to see the new filter.
:)
| Attachment | Size |
|---|---|
| cmf_language_support.patch | 2.06 KB |

#1
Works great for me! Thank you naxoc
Also I've tried to add a language column to the table layout by doing the following:
in the node.inc file
around line 70:
$form['created'][$node->nid] = array('#value' => format_date($node->created, 'small'));$form['language'][$node->nid] = array('#value' => ($node->language));
if (user_access('filter and manage site content')) {
around line 168:
$row[] = drupal_render($form['created'][$key]);$row[] = drupal_render($form['language'][$key]);
if (user_access('filter and manage site content')) {
in the cmf.module file
around line 468:
$header[] = array('data' => t('Time'), 'field' => 'created', 'sort' => 'desc');$header[] = array('data' => t('Lang'), 'field' => 'language');
break;
around line 520:
switch ($kind) {case 'node':
return pager_query('
SELECT n.nid, n.title, n.type, n.language, u.name AS username, u.uid, n.status, n.created, n.changed
FROM {node} n INNER JOIN {users} u ON n.uid = u.uid '. $filter['join'] .
It works but only for node content, I couln't figure out the query to make it work with both content.
Also the title of the column is "Lang" as to save horizontal space since que query is retriving the language as "en", "pt-pt" etc.
I don't know how to make a patch, but since it's an incomplete work, maybe someone can take this and finish it.
#2
Since 5.x does not store the language, this would have to be a 6.x only fix.
@Jolidog: the comment table does not have a language column, so the UNION clause would have to include a dummy column, much like it does for "changed."
#3
For my own reference, if I get commit access:
return pager_query('SELECT 0 AS cid, n.nid, n.title, n.language, NULL AS comment, n.type, u.name AS username,u.uid, n.status, n.created, n.changed
FROM {node} n INNER JOIN {users} u ON n.uid = u.uid '
. $filter['join']
.' '. $where
.' UNION SELECT c.cid, c.nid, c.subject AS title, '' AS language, c.comment, n.type, u.name AS username, u.uid,
c.status, c.timestamp AS created, 0 AS changed
FROM {comments} c INNER JOIN {node} n ON c.nid = n.nid INNER JOIN {users} u ON u.uid = c.uid '
. $filter['join']
.' '. $cwhere
. tablesort_sql($header),
isset($_SESSION['cmf_max_rows']) ? $_SESSION['cmf_max_rows'] : 50, 0, $count_query, $args
$lang_codes = module_exists('locale') ? locale_language_list() : array();$lang_codes[''] = t('Language neutral');
#4
@naxoc: Thank you for the patch, it was helpful.
To both of you: You both obviously know that you have locale enabled, but there are many sites that do not, so there needs to be checks for that. You also didn't seem to realize that sites that never had locale, especially from before D6, had empty values in the language column of the node table, and that should show as "Language neutral."
I worked with your patches and took care of those problems. The fix is committed to 6.x-1.x-dev. Please test it thoroughly.
#5
Thank you NancyDru!
It obvious now that you explained it, my mind is set to being a designer/themer, I try to help, touch the code here and there, but I realy don't know what I'm doing as a developer. :P
I'm going to test the dev version.
#6
Your code above was very good, other than the assumption about the presence of Locale. Even I sometimes do that when I am writing a site-specific module. But, Drupal contrib module maintainers need to consider these things, and many more. I hope I got all the bases covered.
#7
Included in new release.