Hi,
Using flexinode.module and i18n.module I have managed to create multilingual blocks.
Here's what I've done and I'm looking forward to some comments, as I want to know how useful this workaround might be and what kind of polishing it needs :) I'm not a programmer, so please keep your comments simple and understandable...
It started with my wish to have some kind of news / sidenotes / links in the sidebar of my website. Therefore I needed: title, link, date, content.
First I created a flexinode called "sidenote", which got id 2, so let's say flexinode-type 2. As flexinodes are connected with their nodedata, I already had a title and a date. Therefore I defined two additional flexinode fields: link (which was given id 16) and content (which was given id 18). Now I was able to enter the necessary content just as easy as stories, blogposts, et cetera.
Second I had to create some php for the block. Using php I wanted to take care for both logic and themeing. First time ever... But I got it done, wooohaaa! For explaining the basic idea, I will suffice with quoting my code, as the comment lines will explain the logic. I implemented this code as part of a new block, which has been made visible in the right sidebar. Now all content of type sidenote (type 2) is showed as short stories with a title, link, date and content in the right sidebar and, moreover, in the right language as well! I also added a link at the bottom of the sidebar, which links to an overview page using taxonomy terms (this part needs some polishing definitely...).
The result can be found here:
NOTE
At the bottom of the code there are a lot of comment lines; these are for future use, when I want to show certain sidenotes in certain sections, using sections.module.
As said before: I'm looking forward to some feedback, thanks in advance!
Marc
<?php
// determination of the site's language using i18n.
$site_language = _i18n_get_lang();
// definition of flexinode-type for creating content:
// - 2 = custom defined type for nodes in sidebar (sidenotes).
$flexinode_type = 2;
// defintion of flexinode-type fields providing content:
// - 16 = custom defined field for storing weblink;
// - 18 = custom defined field for storing content.
$flexinode_field_link = 16;
$flexinode_field_body = 18;
// initialization of sidebar's block.
$block_initialized = FALSE;
// query:
// selecting (flexi)node data
// where the flexinode-type is the one for sidenotes
// and the node's language is the site's language
// and the node's status is published
// sorted by date created.
$result_fn = db_query
(" SELECT *
FROM {node} n
, {flexinode_data} fn_d
, {flexinode_field} fn_f
, {flexinode_type} fn_t
WHERE fn_t.ctype_id = '$flexinode_type'
AND fn_t.ctype_id = fn_f.ctype_id
AND fn_f.field_id = fn_d.field_id
AND fn_d.nid = n.nid
AND n.language = '$site_language'
AND n.status = 1
ORDER BY n.created DESC
");
// loop for every row of the query above.
// NOTE: one node will have multiple rows,
// namely one for every flexinode field.
// rows for one node are next to each other,
// because of ordering by date and time created.
// the transition from one node to another
// will be determined by comparing:
// - $previous_node;
// - $current_node.
while ($row = db_fetch_object($result_fn))
{
if ($block_initialized == FALSE)
{
// at the start of the first loop,
// the block needs to be initialized:
// row defines $current_node and $previous_node.
$previous_node = $row->created;
$current_node = $row->created;
$block_initialized = TRUE;
}
else
{
// at the start of other loops,
// row defines $current_node only.
$current_node = $row->created;
}
if ($current_node < $previous_node)
{
// if $current_node and $previous_node are not equal,
// the query has just entered the data of another node,
// so the gathered content needs to be printed
// and $previous_node needs to be updated.
print ' ' . $titel . '' . '