function custompage_node_tile in Custom Page 6
Same name and namespace in other branches
- 7 custompage_util.inc \custompage_node_tile()
Parameters
$key : can be $nid of a node or a $title. If $key is not numer, it is assumed to be a title and $type parameter is required. If several nodes with the same title exist, only the first one will be returned.
$type: node type
File
- ./
custompage_util.inc, line 70
Code
function custompage_node_tile($key, $type = '', $teaser_only = FALSE, $show_title = TRUE) {
global $language;
$langcode = $language->language;
//ISO2 code
$default = language_default();
$default_langcode = $default->language;
if (is_numeric($key)) {
$node = node_load(array(
'nid' => $key,
));
}
else {
if (is_string($key) && !empty($type) && is_string($type)) {
$node = node_load(array(
'title' => $key,
'type' => $type,
'language' => $default_langcode,
));
}
}
if (!is_object($node)) {
return ' ';
//We should never return empty string since that makes entire page blank
//due to some weird bug/behaviour in Drupal. Ugh
}
$sql = 'SELECT n.nid FROM {node} n WHERE n.tnid = %d and n.language = \'%s\' ';
$i18n_nid = db_result(db_query(db_rewrite_sql($sql), $node->nid, $langcode));
//defaults should be in default language
if (is_numeric($i18n_nid) && $i18n_nid > 0) {
$node = node_load($i18n_nid);
}
//Serve Default language version (English usually) by default!
if (!$show_title) {
unset($node->title);
}
$content = node_view($node, $teaser_only, TRUE);
$editlink = custompage_edit_link('node/' . $node->nid . '/edit/');
$tile = custompage_tile_wrap($content, $editlink);
return $tile;
}