You are here

function custompage_node_tile in Custom Page 7

Same name and namespace in other branches
  1. 6 custompage_util.inc \custompage_node_tile()

Parameters

$key: can be $nid of a node or a $title. If $key is not numeric, 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($key);
  }
  else {
    if (is_string($key) && !empty($type) && is_string($type)) {
      $entities = entity_load('node', FALSE, $conditions = array(
        'title' => $key,
        'type' => $type,
      ));
      $node = $entities[1];

      //$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 = db_select('node', 'n');
  $sql
    ->fields('n', array(
    'nid',
  ));
  $and = db_and()
    ->condition('tnid', $node->nid)
    ->condition('language', $langcode);
  $sql
    ->condition($and);
  $i18n_nid = $sql
    ->execute()
    ->fetchField();

  //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);
  }
  if ($teaser_only == FALSE) {
    $view_mode = 'full';
  }
  else {
    $view_mode = 'teaser';
  }
  $node_view = node_view($node, $view_mode, $langcode);
  $content = drupal_render($node_view);
  $editlink = custompage_edit_link('node/' . $node->nid . '/edit/');
  $tile = custompage_tile_wrap($content, $editlink);
  return $tile;
}