You are here

public function TMGMTNodeSourcePluginController::getData in Translation Management Tool 7

Returns the data from the fields as a structure that can be processed by the Translation Management system.

Overrides TMGMTSourcePluginControllerInterface::getData

File

sources/node/tmgmt_node.plugin.inc, line 16
Provides the node source plugin controller.

Class

TMGMTNodeSourcePluginController
@file Provides the node source plugin controller.

Code

public function getData(TMGMTJobItem $job_item) {
  $node = node_load($job_item->item_id);
  $source_language = $job_item
    ->getJob()->source_language;
  $languages = language_list();

  // If the node language is not the same as the job source language try to
  // load its translation for the job source language.
  if ($node->language != $source_language) {
    $translation_loaded = FALSE;
    foreach (translation_node_get_translations($node->nid) as $language => $translation) {
      if ($language == $source_language) {
        $node = node_load($translation->nid);
        $translation_loaded = TRUE;
        break;
      }
    }
    if (!$translation_loaded) {
      throw new TMGMTException(t('Unable to load %language translation for the node %title', array(
        '%language' => $languages[$source_language]->name,
        '%title' => $node->title,
      )));
    }
  }
  $type = node_type_get_type($node);

  // Get all the fields that can be translated and arrange their values into
  // a specific structure.
  $structure = tmgmt_field_get_source_data('node', $node, $job_item
    ->getJob()->source_language);
  $structure['node_title']['#label'] = $type->title_label;
  $structure['node_title']['#text'] = $node->title;
  return $structure;
}