You are here

function _rate_get_source_translation in Rate 7

Get entity id for source translation.

This function is safe for use with unsupported entity types.

Parameters

string $entity_type:

int $entity_id:

Return value

int

2 calls to _rate_get_source_translation()
rate_get_results in ./rate.module
Get results for a voting widget.
rate_save_vote in ./rate.module
Save a vote to the database.

File

./rate.module, line 454
Rate module

Code

function _rate_get_source_translation($entity_type, $entity_id) {
  if ($entity_type == 'node' && module_exists('translation')) {
    if (arg(0) == 'node' && arg(1) == $entity_id) {

      // We are on the node page. Use node_load since the node is in static cache.
      $entity_id = node_load($entity_id)->tnid;
    }
    else {

      // We are not on the node page. Do not use node_load to prevent executing many useless queries.
      $tnid = db_select('node', 'n')
        ->fields('n', array(
        'tnid',
      ))
        ->condition('n.nid', $entity_id)
        ->execute()
        ->fetchField();
      if ($tnid) {
        $entity_id = $tnid;
      }
    }
  }
  return $entity_id;
}