You are here

function globallink_send_entity_ref_for_translations in GlobalLink Connect for Drupal 7.7

1 call to globallink_send_entity_ref_for_translations()
globallink_entity_send_for_translations in globallink_entity/globallink_entity.inc
Sends entities for translation.

File

./globallink_background_jobs.inc, line 1331
To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor.

Code

function globallink_send_entity_ref_for_translations($eids, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority, $globallink_arr) {
  module_load_include('inc', 'globallink', 'gl_ws/gl_ws_send_translations');
  module_load_include('inc', 'globallink', 'globallink');
  module_load_include('inc', 'globallink', 'globallink_custom_entity/globallink_custom_entity');
  $submitter = $submission_details['submitter'];
  $drupal_locale_code = globallink_get_drupal_locale_code($source_locale);
  $entity_ref = array();
  foreach ($eids as $eid => $outer_arr) {
    if (count($outer_arr) < 1) {
      continue;
    }
    foreach ($outer_arr as $type => $outervalue) {
      if (count($outervalue) < 1) {
        continue;
      }
      foreach ($outervalue as $innerkey => $entity_id) {
        $reference_entity = entity_load_single($type, $entity_id);
        $rows = globallink_eck_get_sent_rows_by_id($entity_id, $reference_entity->type);
        $target_arr = $target_locale_arr;
        foreach ($rows as $row) {
          if (array_search($row->target_lang_code, $target_locale_arr)) {
            unset($target_arr[$row->target_lang_code]);
            watchdog(GLOBALLINK_MODULE, 'Skipping entity Id - %id for locales %locale', array(
              '%id' => $entity_id,
              '%locale' => $row->target_lang_code,
            ), WATCHDOG_DEBUG);
          }
        }
        if (empty($target_arr)) {
          continue;
        }
        if (empty($target_arr)) {
          watchdog(GLOBALLINK_MODULE, 'No target languages. Skipping nid - %eid', array(
            '%eid' => $entity_id,
          ), WATCHDOG_CRITICAL);
          continue;
        }
        $drupal_target_arr = array();
        foreach ($target_arr as $target_locale) {
          array_push($drupal_target_arr, globallink_get_drupal_locale_code($target_locale));
        }
        $tnid = NULL;
        $tvid = NULL;
        $name = '.xml';
        $xml_targets = globallink_entity_reference_get_xml($reference_entity, $drupal_target_arr, $tnid, $tvid, $name, FALSE, $drupal_locale_code, $type);
        $xml = $xml_targets[0];
        $eck_entity = $xml_targets[1];
        if (!$xml) {
          watchdog(GLOBALLINK_MODULE, 'Cannot create entity XML. Skipping entity type %entitytype entity id - %eid', array(
            '%eid' => $entity_id,
            '%entitytype' => $type,
          ), WATCHDOG_CRITICAL);
          continue;
        }
        $globallink = new GlobalLink();
        $globallink->otherObjectId = $reference_entity->id;
        $globallink->title = isset($reference_entity->title) ? $reference_entity->title : NULL;
        $globallink->type = $reference_entity->type;
        $globallink->metadata = GLOBALLINK_ENTITY_TYPE_ECK_ENTITY;
        $globallink->sourceLocale = $source_locale;
        $globallink->targetLocale = $target_arr;
        $globallink->sourceXML = $xml;
        $globallink->sourceFileName = $name;
        $globallink->submissionName = $submission_name;
        $globallink->submissionPriority = $submission_priority;
        $globallink->dueDate = $due_date;
        $globallink->submissionInstructions = $submission_details['instructions'] . "\nSubmitter: " . $submitter;
        $globallink_arr[GLOBALLINK_ENTITY_TYPE_ENTITY][] = $globallink;
        if (count($eck_entity) > 0) {
          $globallink_arr = globallink_send_entity_ref_for_translations($eck_entity, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority, $globallink_arr);
        }
      }
    }
  }
  return $globallink_arr;
}