You are here

function entity_translation_preprocess_node in Entity Translation 7

Implements hook_preprocess_node().

Alters node template variables to show/replace entity translation metadata.

File

./entity_translation.node.inc, line 174
The node specific translation functions and hook implementations.

Code

function entity_translation_preprocess_node(&$variables) {
  $node = $variables['node'];
  $submitted = variable_get("node_submitted_{$node->type}", TRUE);
  $mode = variable_get("entity_translation_node_metadata_{$node->type}", ENTITY_TRANSLATION_METADATA_HIDE);
  if ($submitted && $mode != ENTITY_TRANSLATION_METADATA_HIDE) {
    global $language_content, $user;
    $handler = entity_translation_get_handler('node', $node);
    $translations = $handler
      ->getTranslations();
    $langcode = $language_content->language;
    if (isset($translations->data[$langcode]) && $langcode != $translations->original) {
      $translation = $translations->data[$langcode];
      $date = format_date($translation['created']);
      $name = FALSE;
      if ($node->uid != $translation['uid']) {
        $account = $user->uid != $translation['uid'] ? user_load($translation['uid']) : $user;
        $name = theme('username', array(
          'account' => $account,
        ));
      }
      switch ($mode) {
        case ENTITY_TRANSLATION_METADATA_SHOW:
          $variables['date'] .= ' (' . t('translated on <em>!date</em>', array(
            '!date' => $date,
          )) . ')';
          if ($name) {
            $variables['name'] .= ' (' . t('translated by !name', array(
              '!name' => $name,
            )) . ')';
          }
          break;
        case ENTITY_TRANSLATION_METADATA_REPLACE:
          $variables['date'] = $date;
          if ($name) {
            $variables['name'] = $name;
          }
          break;
      }
    }
  }
}